blob: 6c60f1f34b3bfb44a8128fc419165f296a3b02ee [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Ta-wei Yen87c49842016-05-13 21:19:52 -070021import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
22
Ta-wei Yen30a69c82016-12-27 14:52:32 -080023import android.Manifest.permission;
Tyler Gunn327a9722019-04-03 15:28:53 -070024import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070025import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080026import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070027import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070028import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070029import android.content.Context;
30import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070031import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070032import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070033import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080034import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070035import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070036import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070037import android.net.Uri;
38import android.os.AsyncResult;
39import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080040import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070041import android.os.Bundle;
42import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070043import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070044import android.os.Looper;
45import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070046import android.os.Messenger;
Tyler Gunn65d45c22017-06-05 11:22:26 -070047import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080048import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070049import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070050import android.os.ServiceManager;
Brad Ebingerdac2f002018-04-03 15:17:52 -070051import android.os.ShellCallback;
Pengquan Meng85728fb2018-03-12 16:31:21 -070052import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070053import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070054import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070055import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070056import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080057import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070058import android.provider.Telephony;
Santos Cordon7a1885b2015-02-03 11:15:19 -080059import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080060import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070061import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070062import android.telephony.CarrierConfigManager;
Michele Berionne0963c862018-11-27 18:57:59 -080063import android.telephony.CarrierRestrictionRules;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070064import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070065import android.telephony.CellInfoGsm;
66import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070067import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070068import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070069import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070070import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080071import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070072import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080073import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070074import android.telephony.NetworkScanRequest;
Michelebcb01bc2019-02-04 11:36:23 -080075import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080076import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070077import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080078import android.telephony.RadioAccessSpecifier;
Tyler Gunn65d45c22017-06-05 11:22:26 -070079import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070080import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080081import android.telephony.SignalStrength;
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 Yu311536f2018-11-26 11:20:48 -080092import android.telephony.data.ApnSetting;
Jack Yu40306fc2019-05-13 16:54:09 -070093import android.telephony.data.ApnSetting.ApnType;
calvinpaneed9ae82018-11-01 19:43:06 +080094import android.telephony.emergency.EmergencyNumber;
Nathan Harold3ff88932018-08-14 10:19:49 -070095import android.telephony.gsm.GsmCellLocation;
Brad Ebinger1c8542e2019-01-14 13:43:14 -080096import android.telephony.ims.ProvisioningManager;
Brad Ebinger4c460712018-10-01 10:40:55 -070097import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080098import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -070099import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800100import android.telephony.ims.aidl.IImsMmTelFeature;
101import android.telephony.ims.aidl.IImsRcsFeature;
102import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger4c460712018-10-01 10:40:55 -0700103import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800104import android.telephony.ims.feature.MmTelFeature;
105import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800106import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700107import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800108import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700109import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800110import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800111import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800112
Brad Ebinger4c460712018-10-01 10:40:55 -0700113import com.android.ims.ImsException;
Andrew Lee312e8172014-10-23 17:01:36 -0700114import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800115import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700116import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700117import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700118import com.android.internal.telephony.CarrierInfoManager;
chen xu02581692018-11-11 19:03:44 -0800119import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700120import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700121import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700122import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800123import com.android.internal.telephony.HalVersion;
Brad Ebinger5ff97f62019-04-23 16:31:13 -0700124import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800125import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700126import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800127import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700128import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100129import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700130import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700131import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700132import com.android.internal.telephony.Phone;
Malcolm Chenf144d942018-08-14 16:00:53 -0700133import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800134import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700135import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700136import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700137import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700138import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700139import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700140import com.android.internal.telephony.ServiceStateTracker;
sqian2fff4a32018-11-05 14:18:37 -0800141import com.android.internal.telephony.SmsApplication;
142import com.android.internal.telephony.SmsApplication.SmsApplicationData;
Amit Mahajan716e76c2019-05-13 13:48:32 -0700143import com.android.internal.telephony.SmsController;
Brad Ebinger5ff97f62019-04-23 16:31:13 -0700144import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800145import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800146import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chen460810d2019-04-10 18:25:07 -0700147import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqian9d4df8b2019-01-15 18:32:07 -0800148import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700149import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebingereb160e22019-01-23 15:06:19 -0800150import com.android.internal.telephony.ims.ImsResolver;
Pengquan Meng92d253b2019-02-06 11:12:53 -0800151import com.android.internal.telephony.metrics.TelephonyMetrics;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700152import com.android.internal.telephony.uicc.IccIoResult;
153import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800154import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700155import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800156import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700157import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800158import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000159import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700160import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800161import com.android.internal.util.HexDump;
Brad Ebinger5ff97f62019-04-23 16:31:13 -0700162import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700163import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800164import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700165import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700166import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800167
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700168import java.io.FileDescriptor;
169import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700170import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800171import java.util.Arrays;
sqian2fff4a32018-11-05 14:18:37 -0800172import java.util.Collection;
sqian03bca152018-12-05 18:48:28 -0800173import java.util.HashMap;
sqian9d4df8b2019-01-15 18:32:07 -0800174import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800175import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100176import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800177import java.util.Map;
Nazanin Bakhshi1f78d7d2019-04-29 17:29:44 -0700178import java.util.NoSuchElementException;
sqian9d4df8b2019-01-15 18:32:07 -0800179import java.util.Set;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700180
181/**
182 * Implementation of the ITelephony interface.
183 */
Santos Cordon117fee72014-05-16 17:56:12 -0700184public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700185 private static final String LOG_TAG = "PhoneInterfaceManager";
186 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
187 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800188 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700189
190 // Message codes used with mMainThreadHandler
191 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700192 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
193 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700194 private static final int CMD_OPEN_CHANNEL = 9;
195 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
196 private static final int CMD_CLOSE_CHANNEL = 11;
197 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800198 private static final int CMD_NV_READ_ITEM = 13;
199 private static final int EVENT_NV_READ_ITEM_DONE = 14;
200 private static final int CMD_NV_WRITE_ITEM = 15;
201 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
202 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
203 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu1cc0abe2018-10-26 17:39:23 -0700204 private static final int CMD_RESET_MODEM_CONFIG = 19;
205 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800206 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
207 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
208 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
209 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800210 private static final int CMD_SEND_ENVELOPE = 25;
211 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000212 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
213 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700214 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
215 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
216 private static final int CMD_EXCHANGE_SIM_IO = 31;
217 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800218 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
219 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700220 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
221 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700222 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
223 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700224 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
225 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
226 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
227 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700228 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
229 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
230 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
231 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700232 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800233 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
234 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000235 private static final int CMD_SWITCH_SLOTS = 50;
236 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700237 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
238 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
239 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
240 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
241 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
242 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
243 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
244 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700245 private static final int CMD_GET_ALL_CELL_INFO = 60;
246 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
247 private static final int CMD_GET_CELL_LOCATION = 62;
248 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu1cc0abe2018-10-26 17:39:23 -0700249 private static final int CMD_MODEM_REBOOT = 64;
250 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700251 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
252 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen509b5b72019-01-15 20:22:16 -0800253 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
254 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshi1f78d7d2019-04-29 17:29:44 -0700255 private static final int CMD_GET_MODEM_STATUS = 70;
256 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700257
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800258 // Parameters of select command.
259 private static final int SELECT_COMMAND = 0xA4;
260 private static final int SELECT_P1 = 0x04;
261 private static final int SELECT_P2 = 0;
262 private static final int SELECT_P3 = 0x10;
263
Pengquan Meng85728fb2018-03-12 16:31:21 -0700264 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
265 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
266 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
267
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700268 /** The singleton instance. */
269 private static PhoneInterfaceManager sInstance;
270
Wink Saville3ab207e2014-11-20 13:07:20 -0800271 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800272 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700273 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800274 private AppOpsManager mAppOps;
275 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800276 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800277 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chenf144d942018-08-14 16:00:53 -0700278 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700279
Derek Tan97ebb422014-09-05 16:55:38 -0700280 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
281 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800282 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800283 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700284
Micheled3107c52018-12-21 15:00:11 -0800285 // String to store multi SIM allowed
286 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
287
Derek Tan740e1672017-06-27 14:56:27 -0700288 // The AID of ISD-R.
289 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
290
yinxub1bed742017-04-17 11:45:04 -0700291 private NetworkScanRequestTracker mNetworkScanRequestTracker;
292
David Kelly5e06a7f2018-03-12 14:10:59 +0000293 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
294 private static final int MANUFACTURER_CODE_LENGTH = 8;
295
Derek Tan89e89d42014-07-08 17:00:10 -0700296 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700297 * A request object to use for transmitting data to an ICC.
298 */
299 private static final class IccAPDUArgument {
300 public int channel, cla, command, p1, p2, p3;
301 public String data;
302
303 public IccAPDUArgument(int channel, int cla, int command,
304 int p1, int p2, int p3, String data) {
305 this.channel = channel;
306 this.cla = cla;
307 this.command = command;
308 this.p1 = p1;
309 this.p2 = p2;
310 this.p3 = p3;
311 this.data = data;
312 }
313 }
314
315 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700316 * A request object to use for transmitting data to an ICC.
317 */
318 private static final class ManualNetworkSelectionArgument {
319 public OperatorInfo operatorInfo;
320 public boolean persistSelection;
321
322 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
323 this.operatorInfo = operatorInfo;
324 this.persistSelection = persistSelection;
325 }
326 }
327
328 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700329 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
330 * request after sending. The main thread will notify the request when it is complete.
331 */
332 private static final class MainThreadRequest {
333 /** The argument to use for the request */
334 public Object argument;
335 /** The result of the request that is run on the main thread */
336 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800337 // The subscriber id that this request applies to. Defaults to
338 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
339 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700340
Nathan Harold92bed182018-10-12 18:16:49 -0700341 // In cases where subId is unavailable, the caller needs to specify the phone.
342 public Phone phone;
343
vagdevie435a3e2018-08-15 16:01:53 -0700344 public WorkSource workSource;
345
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700346 public MainThreadRequest(Object argument) {
347 this.argument = argument;
348 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800349
Nathan Harold92bed182018-10-12 18:16:49 -0700350 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
351 this.argument = argument;
352 if (phone != null) {
353 this.phone = phone;
354 }
355 this.workSource = workSource;
356 }
357
vagdevie435a3e2018-08-15 16:01:53 -0700358 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800359 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800360 if (subId != null) {
361 this.subId = subId;
362 }
vagdevie435a3e2018-08-15 16:01:53 -0700363 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800364 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700365 }
366
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800367 private static final class IncomingThirdPartyCallArgs {
368 public final ComponentName component;
369 public final String callId;
370 public final String callerDisplayName;
371
372 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
373 String callerDisplayName) {
374 this.component = component;
375 this.callId = callId;
376 this.callerDisplayName = callerDisplayName;
377 }
378 }
379
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700380 /**
381 * A handler that processes messages on the main thread in the phone process. Since many
382 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
383 * inbound binder threads to the main thread in the phone process. The Binder thread
384 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
385 * on, which will be notified when the operation completes and will contain the result of the
386 * request.
387 *
388 * <p>If a MainThreadRequest object is provided in the msg.obj field,
389 * note that request.result must be set to something non-null for the calling thread to
390 * unblock.
391 */
392 private final class MainThreadHandler extends Handler {
393 @Override
394 public void handleMessage(Message msg) {
395 MainThreadRequest request;
396 Message onCompleted;
397 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800398 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700399 IccAPDUArgument iccArgument;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800400 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700401
402 switch (msg.what) {
Pengquan Meng0c05b502018-09-06 09:59:22 -0700403 case CMD_HANDLE_USSD_REQUEST: {
404 request = (MainThreadRequest) msg.obj;
405 final Phone phone = getPhoneFromRequest(request);
406 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
407 String ussdRequest = ussdObject.first;
408 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700409
Pengquan Meng0c05b502018-09-06 09:59:22 -0700410 if (!isUssdApiAllowed(request.subId)) {
411 // Carrier does not support use of this API, return failure.
412 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
413 UssdResponse response = new UssdResponse(ussdRequest, null);
414 Bundle returnData = new Bundle();
415 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
416 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700417
Pengquan Meng0c05b502018-09-06 09:59:22 -0700418 request.result = true;
419 notifyRequester(request);
420 return;
421 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700422
Pengquan Meng0c05b502018-09-06 09:59:22 -0700423 try {
424 request.result = phone != null
425 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
426 } catch (CallStateException cse) {
427 request.result = false;
428 }
429 // Wake up the requesting thread
430 notifyRequester(request);
431 break;
pkanwar32d516d2016-10-14 19:37:38 -0700432 }
433
Yorke Lee716f67e2015-06-17 15:39:16 -0700434 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700435 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700436 final Phone phone = getPhoneFromRequest(request);
437 request.result = phone != null ?
438 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
439 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700440 // Wake up the requesting thread
Pengquan Meng0c05b502018-09-06 09:59:22 -0700441 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700442 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700443 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700444
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700445 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700446 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700447 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800448 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700449 if (uiccCard == null) {
450 loge("iccTransmitApduLogicalChannel: No UICC");
451 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700452 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700453 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700454 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
455 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700456 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700457 iccArgument.channel, iccArgument.cla, iccArgument.command,
458 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700459 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700460 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700461 break;
462
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700463 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700464 ar = (AsyncResult) msg.obj;
465 request = (MainThreadRequest) ar.userObj;
466 if (ar.exception == null && ar.result != null) {
467 request.result = ar.result;
468 } else {
469 request.result = new IccIoResult(0x6F, 0, (byte[])null);
470 if (ar.result == null) {
471 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800472 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700473 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800474 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700475 } else {
476 loge("iccTransmitApduLogicalChannel: Unknown exception");
477 }
478 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700479 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700480 break;
481
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700482 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
483 request = (MainThreadRequest) msg.obj;
484 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800485 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700486 if (uiccCard == null) {
487 loge("iccTransmitApduBasicChannel: No UICC");
488 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700489 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700490 } else {
491 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
492 request);
493 uiccCard.iccTransmitApduBasicChannel(
494 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
495 iccArgument.p3, iccArgument.data, onCompleted);
496 }
497 break;
498
499 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
500 ar = (AsyncResult) msg.obj;
501 request = (MainThreadRequest) ar.userObj;
502 if (ar.exception == null && ar.result != null) {
503 request.result = ar.result;
504 } else {
505 request.result = new IccIoResult(0x6F, 0, (byte[])null);
506 if (ar.result == null) {
507 loge("iccTransmitApduBasicChannel: Empty response");
508 } else if (ar.exception instanceof CommandException) {
509 loge("iccTransmitApduBasicChannel: CommandException: " +
510 ar.exception);
511 } else {
512 loge("iccTransmitApduBasicChannel: Unknown exception");
513 }
514 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700515 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700516 break;
517
518 case CMD_EXCHANGE_SIM_IO:
519 request = (MainThreadRequest) msg.obj;
520 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800521 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700522 if (uiccCard == null) {
523 loge("iccExchangeSimIO: No UICC");
524 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700525 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700526 } else {
527 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
528 request);
529 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
530 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
531 iccArgument.data, onCompleted);
532 }
533 break;
534
535 case EVENT_EXCHANGE_SIM_IO_DONE:
536 ar = (AsyncResult) msg.obj;
537 request = (MainThreadRequest) ar.userObj;
538 if (ar.exception == null && ar.result != null) {
539 request.result = ar.result;
540 } else {
541 request.result = new IccIoResult(0x6f, 0, (byte[])null);
542 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700543 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700544 break;
545
Derek Tan4d5e5c12014-02-04 11:54:58 -0800546 case CMD_SEND_ENVELOPE:
547 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800548 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700549 if (uiccCard == null) {
550 loge("sendEnvelopeWithStatus: No UICC");
551 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700552 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700553 } else {
554 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
555 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
556 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800557 break;
558
559 case EVENT_SEND_ENVELOPE_DONE:
560 ar = (AsyncResult) msg.obj;
561 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700562 if (ar.exception == null && ar.result != null) {
563 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800564 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700565 request.result = new IccIoResult(0x6F, 0, (byte[])null);
566 if (ar.result == null) {
567 loge("sendEnvelopeWithStatus: Empty response");
568 } else if (ar.exception instanceof CommandException) {
569 loge("sendEnvelopeWithStatus: CommandException: " +
570 ar.exception);
571 } else {
572 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
573 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800574 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700575 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800576 break;
577
Shishir Agrawal566b7612013-10-28 14:41:00 -0700578 case CMD_OPEN_CHANNEL:
579 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800580 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800581 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700582 if (uiccCard == null) {
583 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800584 request.result = new IccOpenLogicalChannelResponse(-1,
585 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700586 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700587 } else {
588 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800589 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
590 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700591 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700592 break;
593
594 case EVENT_OPEN_CHANNEL_DONE:
595 ar = (AsyncResult) msg.obj;
596 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700597 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700598 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700599 int[] result = (int[]) ar.result;
600 int channelId = result[0];
601 byte[] selectResponse = null;
602 if (result.length > 1) {
603 selectResponse = new byte[result.length - 1];
604 for (int i = 1; i < result.length; ++i) {
605 selectResponse[i - 1] = (byte) result[i];
606 }
607 }
608 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700609 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700610 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700611 if (ar.result == null) {
612 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700613 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700614 if (ar.exception != null) {
615 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
616 }
617
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700618 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700619 if (ar.exception instanceof CommandException) {
620 CommandException.Error error =
621 ((CommandException) (ar.exception)).getCommandError();
622 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700623 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700624 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700625 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700626 }
627 }
628 openChannelResp = new IccOpenLogicalChannelResponse(
629 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700630 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700631 request.result = openChannelResp;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700632 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700633 break;
634
635 case CMD_CLOSE_CHANNEL:
636 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800637 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700638 if (uiccCard == null) {
639 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900640 request.result = false;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700641 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700642 } else {
643 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
644 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
645 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700646 break;
647
648 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800649 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
650 break;
651
652 case CMD_NV_READ_ITEM:
653 request = (MainThreadRequest) msg.obj;
654 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800655 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
656 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800657 break;
658
659 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700660 ar = (AsyncResult) msg.obj;
661 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800662 if (ar.exception == null && ar.result != null) {
663 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700664 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800665 request.result = "";
666 if (ar.result == null) {
667 loge("nvReadItem: Empty response");
668 } else if (ar.exception instanceof CommandException) {
669 loge("nvReadItem: CommandException: " +
670 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700671 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800672 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700673 }
674 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700675 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700676 break;
677
Jake Hambye994d462014-02-03 13:10:13 -0800678 case CMD_NV_WRITE_ITEM:
679 request = (MainThreadRequest) msg.obj;
680 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
681 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800682 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdevie435a3e2018-08-15 16:01:53 -0700683 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800684 break;
685
686 case EVENT_NV_WRITE_ITEM_DONE:
687 handleNullReturnEvent(msg, "nvWriteItem");
688 break;
689
690 case CMD_NV_WRITE_CDMA_PRL:
691 request = (MainThreadRequest) msg.obj;
692 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800693 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800694 break;
695
696 case EVENT_NV_WRITE_CDMA_PRL_DONE:
697 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
698 break;
699
chen xu1cc0abe2018-10-26 17:39:23 -0700700 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800701 request = (MainThreadRequest) msg.obj;
chen xu1cc0abe2018-10-26 17:39:23 -0700702 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800703 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800704 break;
705
chen xu1cc0abe2018-10-26 17:39:23 -0700706 case EVENT_RESET_MODEM_CONFIG_DONE:
707 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800708 break;
709
Jake Hamby7c27be32014-03-03 13:25:59 -0800710 case CMD_GET_PREFERRED_NETWORK_TYPE:
711 request = (MainThreadRequest) msg.obj;
712 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700713 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800714 break;
715
716 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
717 ar = (AsyncResult) msg.obj;
718 request = (MainThreadRequest) ar.userObj;
719 if (ar.exception == null && ar.result != null) {
720 request.result = ar.result; // Integer
721 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800722 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800723 if (ar.result == null) {
724 loge("getPreferredNetworkType: Empty response");
725 } else if (ar.exception instanceof CommandException) {
726 loge("getPreferredNetworkType: CommandException: " +
727 ar.exception);
728 } else {
729 loge("getPreferredNetworkType: Unknown exception");
730 }
731 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700732 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800733 break;
734
735 case CMD_SET_PREFERRED_NETWORK_TYPE:
736 request = (MainThreadRequest) msg.obj;
737 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
738 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700739 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800740 break;
741
742 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
743 handleNullReturnEvent(msg, "setPreferredNetworkType");
744 break;
745
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000746 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
747 request = (MainThreadRequest)msg.obj;
748 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800749 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000750 break;
751
752 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
753 ar = (AsyncResult)msg.obj;
754 request = (MainThreadRequest)ar.userObj;
755 request.result = ar;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700756 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000757 break;
758
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800759 case CMD_SET_VOICEMAIL_NUMBER:
760 request = (MainThreadRequest) msg.obj;
761 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
762 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800763 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
764 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800765 break;
766
767 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
768 handleNullReturnEvent(msg, "setVoicemailNumber");
769 break;
770
Stuart Scott54788802015-03-30 13:18:01 -0700771 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
772 request = (MainThreadRequest) msg.obj;
773 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
774 request);
775 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
776 break;
777
778 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
779 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
780 break;
781
Shishir Agrawal302c8692015-06-19 13:49:39 -0700782 case CMD_PERFORM_NETWORK_SCAN:
783 request = (MainThreadRequest) msg.obj;
784 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
785 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
786 break;
787
788 case EVENT_PERFORM_NETWORK_SCAN_DONE:
789 ar = (AsyncResult) msg.obj;
790 request = (MainThreadRequest) ar.userObj;
791 CellNetworkScanResult cellScanResult;
792 if (ar.exception == null && ar.result != null) {
793 cellScanResult = new CellNetworkScanResult(
794 CellNetworkScanResult.STATUS_SUCCESS,
795 (List<OperatorInfo>) ar.result);
796 } else {
797 if (ar.result == null) {
798 loge("getCellNetworkScanResults: Empty response");
799 }
800 if (ar.exception != null) {
801 loge("getCellNetworkScanResults: Exception: " + ar.exception);
802 }
803 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
804 if (ar.exception instanceof CommandException) {
805 CommandException.Error error =
806 ((CommandException) (ar.exception)).getCommandError();
807 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
808 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
809 } else if (error == CommandException.Error.GENERIC_FAILURE) {
810 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
811 }
812 }
813 cellScanResult = new CellNetworkScanResult(errorCode, null);
814 }
815 request.result = cellScanResult;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700816 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700817 break;
818
819 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
820 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700821 ManualNetworkSelectionArgument selArg =
822 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700823 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
824 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700825 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
826 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700827 break;
828
829 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Mengdd9ac822018-09-20 15:25:35 -0700830 ar = (AsyncResult) msg.obj;
831 request = (MainThreadRequest) ar.userObj;
832 if (ar.exception == null) {
833 request.result = true;
834 } else {
835 request.result = false;
836 loge("setNetworkSelectionModeManual " + ar.exception);
837 }
838 notifyRequester(request);
839 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700840 break;
841
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700842 case CMD_GET_MODEM_ACTIVITY_INFO:
843 request = (MainThreadRequest) msg.obj;
844 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisc56281c2019-04-03 14:18:34 -0700845 if (defaultPhone != null) {
846 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
847 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700848 break;
849
850 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
851 ar = (AsyncResult) msg.obj;
852 request = (MainThreadRequest) ar.userObj;
853 if (ar.exception == null && ar.result != null) {
854 request.result = ar.result;
855 } else {
856 if (ar.result == null) {
857 loge("queryModemActivityInfo: Empty response");
858 } else if (ar.exception instanceof CommandException) {
859 loge("queryModemActivityInfo: CommandException: " +
860 ar.exception);
861 } else {
862 loge("queryModemActivityInfo: Unknown exception");
863 }
864 }
Amit Mahajand4766222016-01-28 15:28:28 -0800865 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
866 if (request.result == null) {
867 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
868 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700869 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700870 break;
871
Meng Wang1a7c35a2016-05-05 20:56:15 -0700872 case CMD_SET_ALLOWED_CARRIERS:
873 request = (MainThreadRequest) msg.obj;
Michele Berionne0963c862018-11-27 18:57:59 -0800874 CarrierRestrictionRules argument =
875 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700876 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne0963c862018-11-27 18:57:59 -0800877 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700878 break;
879
880 case EVENT_SET_ALLOWED_CARRIERS_DONE:
881 ar = (AsyncResult) msg.obj;
882 request = (MainThreadRequest) ar.userObj;
883 if (ar.exception == null && ar.result != null) {
884 request.result = ar.result;
885 } else {
Michele Berionne0963c862018-11-27 18:57:59 -0800886 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
887 if (ar.exception instanceof CommandException) {
888 loge("setAllowedCarriers: CommandException: " + ar.exception);
889 CommandException.Error error =
890 ((CommandException) (ar.exception)).getCommandError();
891 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
892 request.result =
893 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
894 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700895 } else {
896 loge("setAllowedCarriers: Unknown exception");
897 }
898 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700899 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700900 break;
901
902 case CMD_GET_ALLOWED_CARRIERS:
903 request = (MainThreadRequest) msg.obj;
904 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800905 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700906 break;
907
908 case EVENT_GET_ALLOWED_CARRIERS_DONE:
909 ar = (AsyncResult) msg.obj;
910 request = (MainThreadRequest) ar.userObj;
911 if (ar.exception == null && ar.result != null) {
912 request.result = ar.result;
913 } else {
Michele Berionne0963c862018-11-27 18:57:59 -0800914 request.result = new IllegalStateException(
915 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700916 if (ar.result == null) {
917 loge("getAllowedCarriers: Empty response");
918 } else if (ar.exception instanceof CommandException) {
919 loge("getAllowedCarriers: CommandException: " +
920 ar.exception);
921 } else {
922 loge("getAllowedCarriers: Unknown exception");
923 }
924 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700925 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700926 break;
927
Nathan Haroldb3014052017-01-25 15:57:32 -0800928 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
929 ar = (AsyncResult) msg.obj;
930 request = (MainThreadRequest) ar.userObj;
931 if (ar.exception == null && ar.result != null) {
932 request.result = ar.result;
933 } else {
934 request.result = new IllegalArgumentException(
935 "Failed to retrieve Forbidden Plmns");
936 if (ar.result == null) {
937 loge("getForbiddenPlmns: Empty response");
938 } else {
939 loge("getForbiddenPlmns: Unknown exception");
940 }
941 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700942 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800943 break;
944
945 case CMD_GET_FORBIDDEN_PLMNS:
946 request = (MainThreadRequest) msg.obj;
947 uiccCard = getUiccCardFromRequest(request);
948 if (uiccCard == null) {
949 loge("getForbiddenPlmns() UiccCard is null");
950 request.result = new IllegalArgumentException(
951 "getForbiddenPlmns() UiccCard is null");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700952 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800953 break;
954 }
955 Integer appType = (Integer) request.argument;
956 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
957 if (uiccApp == null) {
958 loge("getForbiddenPlmns() no app with specified type -- "
959 + appType);
960 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700961 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800962 break;
963 } else {
964 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
965 + " specified type -- " + appType);
966 }
967 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
968 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
969 onCompleted);
970 break;
971
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000972 case CMD_SWITCH_SLOTS:
973 request = (MainThreadRequest) msg.obj;
974 int[] physicalSlots = (int[]) request.argument;
975 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
976 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
977 break;
978
979 case EVENT_SWITCH_SLOTS_DONE:
980 ar = (AsyncResult) msg.obj;
981 request = (MainThreadRequest) ar.userObj;
982 request.result = (ar.exception == null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700983 notifyRequester(request);
984 break;
985 case CMD_GET_NETWORK_SELECTION_MODE:
986 request = (MainThreadRequest) msg.obj;
987 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
988 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
989 break;
990
991 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
992 ar = (AsyncResult) msg.obj;
993 request = (MainThreadRequest) ar.userObj;
994 if (ar.exception != null) {
995 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
996 } else {
997 int mode = ((int[]) ar.result)[0];
998 if (mode == 0) {
999 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1000 } else {
1001 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1002 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001003 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07001004 notifyRequester(request);
1005 break;
1006 case CMD_GET_CDMA_ROAMING_MODE:
1007 request = (MainThreadRequest) msg.obj;
1008 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1009 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1010 break;
1011 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1012 ar = (AsyncResult) msg.obj;
1013 request = (MainThreadRequest) ar.userObj;
1014 if (ar.exception != null) {
1015 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1016 } else {
1017 request.result = ((int[]) ar.result)[0];
1018 }
1019 notifyRequester(request);
1020 break;
1021 case CMD_SET_CDMA_ROAMING_MODE:
1022 request = (MainThreadRequest) msg.obj;
1023 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1024 int mode = (int) request.argument;
1025 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1026 break;
1027 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1028 ar = (AsyncResult) msg.obj;
1029 request = (MainThreadRequest) ar.userObj;
1030 request.result = ar.exception == null;
1031 notifyRequester(request);
1032 break;
1033 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1034 request = (MainThreadRequest) msg.obj;
1035 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1036 int subscriptionMode = (int) request.argument;
1037 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1038 break;
1039 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1040 ar = (AsyncResult) msg.obj;
1041 request = (MainThreadRequest) ar.userObj;
1042 request.result = ar.exception == null;
1043 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001044 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001045 case CMD_GET_ALL_CELL_INFO:
1046 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001047 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001048 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001049 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001050 case EVENT_GET_ALL_CELL_INFO_DONE:
1051 ar = (AsyncResult) msg.obj;
1052 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001053 // If a timeout occurs, the response will be null
1054 request.result = (ar.exception == null && ar.result != null)
1055 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001056 synchronized (request) {
1057 request.notifyAll();
1058 }
1059 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001060 case CMD_REQUEST_CELL_INFO_UPDATE:
1061 request = (MainThreadRequest) msg.obj;
1062 request.phone.requestCellInfoUpdate(request.workSource,
1063 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1064 break;
1065 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1066 ar = (AsyncResult) msg.obj;
1067 request = (MainThreadRequest) ar.userObj;
1068 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1069 try {
1070 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001071 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Nathan Harolde82c4b82018-12-18 19:40:37 -08001072 cb.onError(TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1073 new android.os.ParcelableException(ar.exception));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001074 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001075 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Nathan Harolde82c4b82018-12-18 19:40:37 -08001076 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001077 } else {
1078 // use the result as returned
1079 cb.onCellInfo((List<CellInfo>) ar.result);
1080 }
1081 } catch (RemoteException re) {
1082 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1083 }
1084 break;
1085 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001086 request = (MainThreadRequest) msg.obj;
1087 WorkSource ws = (WorkSource) request.argument;
1088 Phone phone = getPhoneFromRequest(request);
1089 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1090 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001091 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001092 ar = (AsyncResult) msg.obj;
1093 request = (MainThreadRequest) ar.userObj;
1094 if (ar.exception == null) {
1095 request.result = ar.result;
1096 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001097 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001098 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1099 ? new CdmaCellLocation() : new GsmCellLocation();
1100 }
1101
1102 synchronized (request) {
1103 request.notifyAll();
1104 }
1105 break;
chen xu1cc0abe2018-10-26 17:39:23 -07001106 case CMD_MODEM_REBOOT:
1107 request = (MainThreadRequest) msg.obj;
1108 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001109 defaultPhone.rebootModem(onCompleted);
chen xu1cc0abe2018-10-26 17:39:23 -07001110 break;
chen xu1cc0abe2018-10-26 17:39:23 -07001111 case EVENT_CMD_MODEM_REBOOT_DONE:
1112 handleNullReturnEvent(msg, "rebootModem");
1113 break;
Malcolm Chen509b5b72019-01-15 20:22:16 -08001114 case CMD_REQUEST_ENABLE_MODEM:
1115 request = (MainThreadRequest) msg.obj;
1116 boolean enable = (boolean) request.argument;
1117 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi9b379572019-03-01 17:27:47 -08001118 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen509b5b72019-01-15 20:22:16 -08001119 PhoneConfigurationManager.getInstance()
1120 .enablePhone(request.phone, enable, onCompleted);
1121 break;
1122 case EVENT_ENABLE_MODEM_DONE:
1123 ar = (AsyncResult) msg.obj;
1124 request = (MainThreadRequest) ar.userObj;
1125 request.result = (ar.exception == null);
Nazanin Bakhshi1f78d7d2019-04-29 17:29:44 -07001126 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi9b379572019-03-01 17:27:47 -08001127 //update the cache as modem status has changed
Nazanin Bakhshi1f78d7d2019-04-29 17:29:44 -07001128 if ((boolean) request.result) {
1129 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1130 updateModemStateMetrics();
1131 } else {
1132 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1133 + ar.exception);
1134 }
1135 notifyRequester(request);
1136 break;
1137 case CMD_GET_MODEM_STATUS:
1138 request = (MainThreadRequest) msg.obj;
1139 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1140 PhoneConfigurationManager.getInstance()
1141 .getPhoneStatusFromModem(request.phone, onCompleted);
1142 break;
1143 case EVENT_GET_MODEM_STATUS_DONE:
1144 ar = (AsyncResult) msg.obj;
1145 request = (MainThreadRequest) ar.userObj;
1146 int id = request.phone.getPhoneId();
1147 if (ar.exception == null && ar.result != null) {
1148 request.result = ar.result;
1149 //update the cache as modem status has changed
1150 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1151 (boolean) request.result);
1152 } else {
1153 // Return true if modem status cannot be retrieved. For most cases,
1154 // modem status is on. And for older version modems, GET_MODEM_STATUS
1155 // and disable modem are not supported. Modem is always on.
1156 // TODO: this should be fixed in R to support a third
1157 // status UNKNOWN b/131631629
1158 request.result = true;
1159 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1160 + ar.exception);
1161 }
Malcolm Chen509b5b72019-01-15 20:22:16 -08001162 notifyRequester(request);
1163 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001164 default:
1165 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1166 break;
1167 }
1168 }
Jake Hambye994d462014-02-03 13:10:13 -08001169
Pengquan Meng0c05b502018-09-06 09:59:22 -07001170 private void notifyRequester(MainThreadRequest request) {
1171 synchronized (request) {
1172 request.notifyAll();
1173 }
1174 }
1175
Jake Hambye994d462014-02-03 13:10:13 -08001176 private void handleNullReturnEvent(Message msg, String command) {
1177 AsyncResult ar = (AsyncResult) msg.obj;
1178 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1179 if (ar.exception == null) {
1180 request.result = true;
1181 } else {
1182 request.result = false;
1183 if (ar.exception instanceof CommandException) {
1184 loge(command + ": CommandException: " + ar.exception);
1185 } else {
1186 loge(command + ": Unknown exception");
1187 }
1188 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07001189 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001190 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001191 }
1192
1193 /**
1194 * Posts the specified command to be executed on the main thread,
1195 * waits for the request to complete, and returns the result.
1196 * @see #sendRequestAsync
1197 */
1198 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001199 return sendRequest(
1200 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdevie435a3e2018-08-15 16:01:53 -07001201 }
1202
1203 /**
1204 * Posts the specified command to be executed on the main thread,
1205 * waits for the request to complete, and returns the result.
1206 * @see #sendRequestAsync
1207 */
1208 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1209 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001210 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001211 }
1212
1213 /**
1214 * Posts the specified command to be executed on the main thread,
1215 * waits for the request to complete, and returns the result.
1216 * @see #sendRequestAsync
1217 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001218 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001219 return sendRequest(command, argument, subId, null, null);
vagdevie435a3e2018-08-15 16:01:53 -07001220 }
1221
1222 /**
1223 * Posts the specified command to be executed on the main thread,
1224 * waits for the request to complete, and returns the result.
1225 * @see #sendRequestAsync
1226 */
Nathan Harold92bed182018-10-12 18:16:49 -07001227 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1228 return sendRequest(command, argument, subId, null, workSource);
1229 }
1230
1231 /**
1232 * Posts the specified command to be executed on the main thread,
1233 * waits for the request to complete, and returns the result.
1234 * @see #sendRequestAsync
1235 */
1236 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1237 return sendRequest(
1238 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1239 }
1240
1241 /**
1242 * Posts the specified command to be executed on the main thread,
1243 * waits for the request to complete, and returns the result.
1244 * @see #sendRequestAsync
1245 */
1246 private Object sendRequest(
1247 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001248 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1249 throw new RuntimeException("This method will deadlock if called from the main thread.");
1250 }
1251
Nathan Harold92bed182018-10-12 18:16:49 -07001252 MainThreadRequest request = null;
1253 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1254 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1255 } else if (phone != null) {
1256 request = new MainThreadRequest(argument, phone, workSource);
1257 } else {
1258 request = new MainThreadRequest(argument, subId, workSource);
1259 }
1260
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001261 Message msg = mMainThreadHandler.obtainMessage(command, request);
1262 msg.sendToTarget();
1263
1264 // Wait for the request to complete
1265 synchronized (request) {
1266 while (request.result == null) {
1267 try {
1268 request.wait();
1269 } catch (InterruptedException e) {
1270 // Do nothing, go back and wait until the request is complete
1271 }
1272 }
1273 }
1274 return request.result;
1275 }
1276
1277 /**
1278 * Asynchronous ("fire and forget") version of sendRequest():
1279 * Posts the specified command to be executed on the main thread, and
1280 * returns immediately.
1281 * @see #sendRequest
1282 */
1283 private void sendRequestAsync(int command) {
1284 mMainThreadHandler.sendEmptyMessage(command);
1285 }
1286
1287 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001288 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001289 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001290 */
1291 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001292 sendRequestAsync(command, argument, null, null);
1293 }
1294
1295 /**
1296 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1297 * @see {@link #sendRequest(int,Object)}
1298 */
1299 private void sendRequestAsync(
1300 int command, Object argument, Phone phone, WorkSource workSource) {
1301 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001302 Message msg = mMainThreadHandler.obtainMessage(command, request);
1303 msg.sendToTarget();
1304 }
1305
1306 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001307 * Initialize the singleton PhoneInterfaceManager instance.
1308 * This is only done once, at startup, from PhoneApp.onCreate().
1309 */
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001310 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001311 synchronized (PhoneInterfaceManager.class) {
1312 if (sInstance == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001313 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001314 } else {
1315 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1316 }
1317 return sInstance;
1318 }
1319 }
1320
1321 /** Private constructor; @see init() */
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001322 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001323 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001324 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001325 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001326 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1327 mMainThreadHandler = new MainThreadHandler();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001328 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001329 mTelephonySharedPreferences =
1330 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001331 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chenf144d942018-08-14 16:00:53 -07001332 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001333
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001334 publish();
1335 }
1336
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001337 private Phone getDefaultPhone() {
1338 Phone thePhone = getPhone(getDefaultSubscription());
1339 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1340 }
1341
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001342 private void publish() {
1343 if (DBG) log("publish: " + this);
1344
1345 ServiceManager.addService("phone", this);
1346 }
1347
Stuart Scott584921c2015-01-15 17:10:34 -08001348 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu73b078d2019-02-28 12:03:40 -08001349 if (request.phone != null) {
1350 return request.phone;
1351 } else {
1352 return getPhoneFromSubId(request.subId);
1353 }
1354 }
1355
1356 private Phone getPhoneFromSubId(int subId) {
1357 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1358 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001359 }
1360
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001361 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1362 Phone phone = getPhoneFromRequest(request);
1363 return phone == null ? null :
1364 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1365 }
1366
Wink Saville36469e72014-06-11 15:17:00 -07001367 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001368 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001369 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001370 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001371
1372 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001373 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001374 }
1375
Wink Savilleb564aae2014-10-23 10:18:09 -07001376 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001377 if (DBG) log("dial: " + number);
1378 // No permission check needed here: This is just a wrapper around the
1379 // ACTION_DIAL intent, which is available to any app since it puts up
1380 // the UI before it does anything.
1381
Malcolm Chend965c8b2018-02-28 15:00:40 -08001382 final long identity = Binder.clearCallingIdentity();
1383 try {
1384 String url = createTelUrl(number);
1385 if (url == null) {
1386 return;
1387 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001388
Malcolm Chend965c8b2018-02-28 15:00:40 -08001389 // PENDING: should we just silently fail if phone is offhook or ringing?
1390 PhoneConstants.State state = mCM.getState(subId);
1391 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1392 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1393 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1394 mApp.startActivity(intent);
1395 }
1396 } finally {
1397 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001398 }
1399 }
1400
1401 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001402 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001403 }
1404
Wink Savilleb564aae2014-10-23 10:18:09 -07001405 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001406 if (DBG) log("call: " + number);
1407
1408 // This is just a wrapper around the ACTION_CALL intent, but we still
1409 // need to do a permission check since we're calling startActivity()
1410 // from the context of the phone app.
1411 enforceCallPermission();
1412
1413 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1414 != AppOpsManager.MODE_ALLOWED) {
1415 return;
1416 }
1417
Malcolm Chend965c8b2018-02-28 15:00:40 -08001418 final long identity = Binder.clearCallingIdentity();
1419 try {
1420 String url = createTelUrl(number);
1421 if (url == null) {
1422 return;
1423 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001424
Malcolm Chend965c8b2018-02-28 15:00:40 -08001425 boolean isValid = false;
1426 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1427 if (slist != null) {
1428 for (SubscriptionInfo subInfoRecord : slist) {
1429 if (subInfoRecord.getSubscriptionId() == subId) {
1430 isValid = true;
1431 break;
1432 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001433 }
Wink Saville08874612014-08-31 19:19:58 -07001434 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001435 if (!isValid) {
1436 return;
1437 }
Wink Saville08874612014-08-31 19:19:58 -07001438
Malcolm Chend965c8b2018-02-28 15:00:40 -08001439 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1440 intent.putExtra(SUBSCRIPTION_KEY, subId);
1441 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1442 mApp.startActivity(intent);
1443 } finally {
1444 Binder.restoreCallingIdentity(identity);
1445 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001446 }
1447
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001448 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001449 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001450 }
1451
Wink Savilleb564aae2014-10-23 10:18:09 -07001452 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001453 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001454 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1455 }
1456
1457 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001458 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001459 }
1460
Wink Savilleb564aae2014-10-23 10:18:09 -07001461 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001462 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001463 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1464 }
1465
1466 /** {@hide} */
1467 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001468 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001469 }
1470
Wink Savilleb564aae2014-10-23 10:18:09 -07001471 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001472 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001473
1474 final long identity = Binder.clearCallingIdentity();
1475 try {
1476 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1477 checkSimPin.start();
1478 return checkSimPin.unlockSim(null, pin);
1479 } finally {
1480 Binder.restoreCallingIdentity(identity);
1481 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001482 }
1483
Wink Saville9de0f752013-10-22 19:04:03 -07001484 /** {@hide} */
1485 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001486 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001487 }
1488
Wink Savilleb564aae2014-10-23 10:18:09 -07001489 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001490 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001491
1492 final long identity = Binder.clearCallingIdentity();
1493 try {
1494 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1495 checkSimPuk.start();
1496 return checkSimPuk.unlockSim(puk, pin);
1497 } finally {
1498 Binder.restoreCallingIdentity(identity);
1499 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001500 }
1501
1502 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001503 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001504 * a synchronous one.
1505 */
1506 private static class UnlockSim extends Thread {
1507
1508 private final IccCard mSimCard;
1509
1510 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001511 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1512 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001513
1514 // For replies from SimCard interface
1515 private Handler mHandler;
1516
1517 // For async handler to identify request type
1518 private static final int SUPPLY_PIN_COMPLETE = 100;
1519
1520 public UnlockSim(IccCard simCard) {
1521 mSimCard = simCard;
1522 }
1523
1524 @Override
1525 public void run() {
1526 Looper.prepare();
1527 synchronized (UnlockSim.this) {
1528 mHandler = new Handler() {
1529 @Override
1530 public void handleMessage(Message msg) {
1531 AsyncResult ar = (AsyncResult) msg.obj;
1532 switch (msg.what) {
1533 case SUPPLY_PIN_COMPLETE:
1534 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1535 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001536 mRetryCount = msg.arg1;
1537 if (ar.exception != null) {
1538 if (ar.exception instanceof CommandException &&
1539 ((CommandException)(ar.exception)).getCommandError()
1540 == CommandException.Error.PASSWORD_INCORRECT) {
1541 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1542 } else {
1543 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1544 }
1545 } else {
1546 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1547 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001548 mDone = true;
1549 UnlockSim.this.notifyAll();
1550 }
1551 break;
1552 }
1553 }
1554 };
1555 UnlockSim.this.notifyAll();
1556 }
1557 Looper.loop();
1558 }
1559
1560 /*
1561 * Use PIN or PUK to unlock SIM card
1562 *
1563 * If PUK is null, unlock SIM card with PIN
1564 *
1565 * If PUK is not null, unlock SIM card with PUK and set PIN code
1566 */
Wink Saville9de0f752013-10-22 19:04:03 -07001567 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001568
1569 while (mHandler == null) {
1570 try {
1571 wait();
1572 } catch (InterruptedException e) {
1573 Thread.currentThread().interrupt();
1574 }
1575 }
1576 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1577
1578 if (puk == null) {
1579 mSimCard.supplyPin(pin, callback);
1580 } else {
1581 mSimCard.supplyPuk(puk, pin, callback);
1582 }
1583
1584 while (!mDone) {
1585 try {
1586 Log.d(LOG_TAG, "wait for done");
1587 wait();
1588 } catch (InterruptedException e) {
1589 // Restore the interrupted status
1590 Thread.currentThread().interrupt();
1591 }
1592 }
1593 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001594 int[] resultArray = new int[2];
1595 resultArray[0] = mResult;
1596 resultArray[1] = mRetryCount;
1597 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001598 }
1599 }
1600
1601 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001602 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001603
1604 }
1605
Wink Savilleb564aae2014-10-23 10:18:09 -07001606 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001607 // No permission check needed here: this call is harmless, and it's
1608 // needed for the ServiceState.requestStateUpdate() call (which is
1609 // already intentionally exposed to 3rd parties.)
Malcolm Chend965c8b2018-02-28 15:00:40 -08001610 final long identity = Binder.clearCallingIdentity();
1611 try {
1612 final Phone phone = getPhone(subId);
1613 if (phone != null) {
1614 phone.updateServiceLocation();
1615 }
1616 } finally {
1617 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001618 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001619 }
1620
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001621 @Override
1622 public boolean isRadioOn(String callingPackage) {
1623 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001624 }
1625
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001626 @Override
1627 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001628 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001629 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001630 return false;
1631 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001632
1633 final long identity = Binder.clearCallingIdentity();
1634 try {
1635 return isRadioOnForSubscriber(subId);
1636 } finally {
1637 Binder.restoreCallingIdentity(identity);
1638 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001639 }
1640
1641 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001642 final long identity = Binder.clearCallingIdentity();
1643 try {
1644 final Phone phone = getPhone(subId);
1645 if (phone != null) {
1646 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1647 } else {
1648 return false;
1649 }
1650 } finally {
1651 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001652 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001653 }
1654
1655 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001656 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001657 }
Wink Saville36469e72014-06-11 15:17:00 -07001658
Wink Savilleb564aae2014-10-23 10:18:09 -07001659 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001660 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001661
1662 final long identity = Binder.clearCallingIdentity();
1663 try {
1664 final Phone phone = getPhone(subId);
1665 if (phone != null) {
1666 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1667 }
1668 } finally {
1669 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001670 }
Wink Saville36469e72014-06-11 15:17:00 -07001671 }
1672
1673 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001674 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001675 }
1676
Wink Savilleb564aae2014-10-23 10:18:09 -07001677 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001678 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001679
1680 final long identity = Binder.clearCallingIdentity();
1681 try {
1682 final Phone phone = getPhone(subId);
1683 if (phone == null) {
1684 return false;
1685 }
1686 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1687 toggleRadioOnOffForSubscriber(subId);
1688 }
1689 return true;
1690 } finally {
1691 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001692 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001693 }
Wink Saville36469e72014-06-11 15:17:00 -07001694
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001695 public boolean needMobileRadioShutdown() {
1696 /*
1697 * If any of the Radios are available, it will need to be
1698 * shutdown. So return true if any Radio is available.
1699 */
Malcolm Chend965c8b2018-02-28 15:00:40 -08001700 final long identity = Binder.clearCallingIdentity();
1701 try {
1702 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1703 Phone phone = PhoneFactory.getPhone(i);
1704 if (phone != null && phone.isRadioAvailable()) return true;
1705 }
1706 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1707 return false;
1708 } finally {
1709 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001710 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001711 }
1712
Malcolm Chend965c8b2018-02-28 15:00:40 -08001713 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001714 public void shutdownMobileRadios() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001715 enforceModifyPermission();
1716
1717 final long identity = Binder.clearCallingIdentity();
1718 try {
1719 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1720 logv("Shutting down Phone " + i);
1721 shutdownRadioUsingPhoneId(i);
1722 }
1723 } finally {
1724 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001725 }
1726 }
1727
1728 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001729 Phone phone = PhoneFactory.getPhone(phoneId);
1730 if (phone != null && phone.isRadioAvailable()) {
1731 phone.shutdownRadio();
1732 }
1733 }
1734
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001735 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001736 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001737
1738 final long identity = Binder.clearCallingIdentity();
1739 try {
1740 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1741 if (defaultPhone != null) {
1742 defaultPhone.setRadioPower(turnOn);
1743 return true;
1744 } else {
1745 loge("There's no default phone.");
1746 return false;
1747 }
1748 } finally {
1749 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001750 }
Wink Saville36469e72014-06-11 15:17:00 -07001751 }
1752
Wink Savilleb564aae2014-10-23 10:18:09 -07001753 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001754 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001755
1756 final long identity = Binder.clearCallingIdentity();
1757 try {
1758 final Phone phone = getPhone(subId);
1759 if (phone != null) {
1760 phone.setRadioPower(turnOn);
1761 return true;
1762 } else {
1763 return false;
1764 }
1765 } finally {
1766 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001767 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001768 }
1769
Wink Saville36469e72014-06-11 15:17:00 -07001770 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001771 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001772 public boolean enableDataConnectivity() {
1773 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001774
1775 final long identity = Binder.clearCallingIdentity();
1776 try {
1777 int subId = mSubscriptionController.getDefaultDataSubId();
1778 final Phone phone = getPhone(subId);
1779 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08001780 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001781 return true;
1782 } else {
1783 return false;
1784 }
1785 } finally {
1786 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001787 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001788 }
1789
Wink Saville36469e72014-06-11 15:17:00 -07001790 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001791 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001792 public boolean disableDataConnectivity() {
1793 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001794
1795 final long identity = Binder.clearCallingIdentity();
1796 try {
1797 int subId = mSubscriptionController.getDefaultDataSubId();
1798 final Phone phone = getPhone(subId);
1799 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08001800 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001801 return true;
1802 } else {
1803 return false;
1804 }
1805 } finally {
1806 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001807 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001808 }
1809
Sanket Padawe356d7632015-06-22 14:03:32 -07001810 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001811 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001812 final long identity = Binder.clearCallingIdentity();
1813 try {
1814 final Phone phone = getPhone(subId);
1815 if (phone != null) {
Jack Yu311536f2018-11-26 11:20:48 -08001816 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001817 } else {
1818 return false;
1819 }
1820 } finally {
1821 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001822 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001823 }
1824
1825 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001826 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001827 }
1828
pkanwarae03a6b2016-11-06 20:37:09 -08001829 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001830 enforceCallPermission();
1831
1832 final long identity = Binder.clearCallingIdentity();
1833 try {
1834 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1835 return;
1836 }
1837 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1838 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1839 } finally {
1840 Binder.restoreCallingIdentity(identity);
1841 }
pkanwar32d516d2016-10-14 19:37:38 -07001842 };
1843
Wink Savilleb564aae2014-10-23 10:18:09 -07001844 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001845 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001846
1847 final long identity = Binder.clearCallingIdentity();
1848 try {
1849 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1850 return false;
1851 }
1852 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1853 } finally {
1854 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001855 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001856 }
1857
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001858 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001859 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001860 }
1861
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001862 public int getCallStateForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001863 final long identity = Binder.clearCallingIdentity();
1864 try {
1865 Phone phone = PhoneFactory.getPhone(slotIndex);
1866 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1867 PhoneConstantConversions.convertCallState(phone.getState());
1868 } finally {
1869 Binder.restoreCallingIdentity(identity);
1870 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001871 }
1872
Sanket Padawe356d7632015-06-22 14:03:32 -07001873 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001874 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001875 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
1876 }
1877
1878 @Override
1879 public int getDataStateForSubId(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001880 final long identity = Binder.clearCallingIdentity();
1881 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001882 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001883 if (phone != null) {
1884 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1885 } else {
1886 return PhoneConstantConversions.convertDataState(
1887 PhoneConstants.DataState.DISCONNECTED);
1888 }
1889 } finally {
1890 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001891 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001892 }
1893
Sanket Padawe356d7632015-06-22 14:03:32 -07001894 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001895 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001896 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
1897 }
1898
1899 @Override
1900 public int getDataActivityForSubId(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001901 final long identity = Binder.clearCallingIdentity();
1902 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001903 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001904 if (phone != null) {
1905 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1906 } else {
1907 return TelephonyManager.DATA_ACTIVITY_NONE;
1908 }
1909 } finally {
1910 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001911 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001912 }
1913
1914 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001915 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001916 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001917 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08001918
1919 LocationAccessPolicy.LocationPermissionResult locationResult =
1920 LocationAccessPolicy.checkLocationPermission(mApp,
1921 new LocationAccessPolicy.LocationPermissionQuery.Builder()
1922 .setCallingPackage(callingPackage)
1923 .setCallingPid(Binder.getCallingPid())
1924 .setCallingUid(Binder.getCallingUid())
1925 .setMethod("getCellLocation")
1926 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
1927 .build());
1928 switch (locationResult) {
1929 case DENIED_HARD:
1930 throw new SecurityException("Not allowed to access cell location");
1931 case DENIED_SOFT:
1932 return new Bundle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001933 }
1934
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001935 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08001936 final long identity = Binder.clearCallingIdentity();
1937 try {
1938 if (DBG_LOC) log("getCellLocation: is active user");
1939 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001940 int subId = mSubscriptionController.getDefaultDataSubId();
1941 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1942 cl.fillInNotifierBundle(data);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001943 return data;
1944 } finally {
1945 Binder.restoreCallingIdentity(identity);
1946 }
Svetoslav64fad262015-04-14 14:35:21 -07001947 }
1948
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001949 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001950 public String getNetworkCountryIsoForPhone(int phoneId) {
1951 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1952 // registered cell info, so return a NULL country instead.
1953 final long identity = Binder.clearCallingIdentity();
1954 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001955 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1956 // Get default phone in this case.
1957 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1958 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001959 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001960 // Todo: fix this when we can get the actual cellular network info when the device
1961 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001962 if (TelephonyManager.NETWORK_TYPE_IWLAN
1963 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1964 return "";
1965 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001966 Phone phone = PhoneFactory.getPhone(phoneId);
1967 if (phone != null) {
1968 ServiceStateTracker sst = phone.getServiceStateTracker();
1969 if (sst != null) {
1970 LocaleTracker lt = sst.getLocaleTracker();
1971 if (lt != null) {
1972 return lt.getCurrentCountry();
1973 }
1974 }
1975 }
1976 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001977 } finally {
1978 Binder.restoreCallingIdentity(identity);
1979 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001980 }
1981
1982 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001983 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001984 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001985 }
1986
Sanket Padawe356d7632015-06-22 14:03:32 -07001987 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001988 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001989 mApp.enforceCallingOrSelfPermission(
1990 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001991
1992 final long identity = Binder.clearCallingIdentity();
1993 try {
1994 final Phone phone = getPhone(subId);
1995 if (phone != null) {
1996 phone.enableLocationUpdates();
1997 }
1998 } finally {
1999 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002000 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002001 }
2002
2003 @Override
2004 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002005 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002006 }
2007
Sanket Padawe356d7632015-06-22 14:03:32 -07002008 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002009 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002010 mApp.enforceCallingOrSelfPermission(
2011 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002012
2013 final long identity = Binder.clearCallingIdentity();
2014 try {
2015 final Phone phone = getPhone(subId);
2016 if (phone != null) {
2017 phone.disableLocationUpdates();
2018 }
2019 } finally {
2020 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002021 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002022 }
2023
Nathan Harold31d7ff32018-10-15 20:20:30 -07002024 /**
2025 * Returns the target SDK version number for a given package name.
2026 *
2027 * @return target SDK if the package is found or INT_MAX.
2028 */
2029 private int getTargetSdk(String packageName) {
2030 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002031 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(
2032 packageName, 0);
Nathan Harold31d7ff32018-10-15 20:20:30 -07002033 if (ai != null) return ai.targetSdkVersion;
2034 } catch (PackageManager.NameNotFoundException unexpected) {
2035 }
2036 return Integer.MAX_VALUE;
2037 }
2038
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002039 @Override
2040 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07002041 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
2042 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002043 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2044 throw new SecurityException(
2045 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2046 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002047
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002048 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
2049 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2050 return null;
2051 }
Svetoslav64fad262015-04-14 14:35:21 -07002052
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002053 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002054
Nathan Haroldf180aac2018-06-01 18:43:55 -07002055 List<CellInfo> info = getAllCellInfo(callingPackage);
2056 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002057
Nathan Haroldf180aac2018-06-01 18:43:55 -07002058 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2059 for (CellInfo ci : info) {
2060 if (ci instanceof CellInfoGsm) {
2061 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2062 } else if (ci instanceof CellInfoWcdma) {
2063 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2064 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002065 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002066 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002067 }
2068
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002069 private List<CellInfo> getCachedCellInfo() {
2070 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2071 for (Phone phone : PhoneFactory.getPhones()) {
2072 List<CellInfo> info = phone.getAllCellInfo();
2073 if (info != null) cellInfos.addAll(info);
2074 }
2075 return cellInfos;
2076 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002077
2078 @Override
Svetoslav64fad262015-04-14 14:35:21 -07002079 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002080 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002081 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002082
2083 LocationAccessPolicy.LocationPermissionResult locationResult =
2084 LocationAccessPolicy.checkLocationPermission(mApp,
2085 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2086 .setCallingPackage(callingPackage)
2087 .setCallingPid(Binder.getCallingPid())
2088 .setCallingUid(Binder.getCallingUid())
2089 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002090 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002091 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2092 .build());
2093 switch (locationResult) {
2094 case DENIED_HARD:
2095 throw new SecurityException("Not allowed to access cell info");
2096 case DENIED_SOFT:
2097 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002098 }
2099
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002100 final int targetSdk = getTargetSdk(callingPackage);
2101 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2102 return getCachedCellInfo();
2103 }
2104
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002105 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002106 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08002107 final long identity = Binder.clearCallingIdentity();
2108 try {
2109 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2110 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002111 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002112 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002113 if (info != null) cellInfos.addAll(info);
2114 }
2115 return cellInfos;
2116 } finally {
2117 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002118 }
2119 }
2120
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002121 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002122 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2123 requestCellInfoUpdateInternal(
2124 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2125 }
2126
2127 @Override
2128 public void requestCellInfoUpdateWithWorkSource(
2129 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2130 enforceModifyPermission();
2131 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2132 }
2133
2134 private void requestCellInfoUpdateInternal(
2135 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002136 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002137 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002138
2139 LocationAccessPolicy.LocationPermissionResult locationResult =
2140 LocationAccessPolicy.checkLocationPermission(mApp,
2141 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2142 .setCallingPackage(callingPackage)
2143 .setCallingPid(Binder.getCallingPid())
2144 .setCallingUid(Binder.getCallingUid())
2145 .setMethod("requestCellInfoUpdate")
2146 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2147 .build());
2148 switch (locationResult) {
2149 case DENIED_HARD:
2150 throw new SecurityException("Not allowed to access cell info");
2151 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002152 try {
2153 cb.onCellInfo(new ArrayList<CellInfo>());
2154 } catch (RemoteException re) {
2155 // Drop without consequences
2156 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002157 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002158 }
2159
Nathan Harolda939a962019-05-09 10:13:47 -07002160
2161 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002162 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2163
2164 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2165 }
2166
2167 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002168 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002169 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002170 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08002171
2172 final long identity = Binder.clearCallingIdentity();
2173 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002174 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002175 } finally {
2176 Binder.restoreCallingIdentity(identity);
2177 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002178 }
2179
Shishir Agrawala9f32182016-04-12 12:00:16 -07002180 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002181 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002182 Phone phone = PhoneFactory.getPhone(slotIndex);
2183 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002184 return null;
2185 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002186 int subId = phone.getSubId();
2187 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2188 mApp, subId, callingPackage, "getImeiForSlot")) {
2189 return null;
2190 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002191
2192 final long identity = Binder.clearCallingIdentity();
2193 try {
2194 return phone.getImei();
2195 } finally {
2196 Binder.restoreCallingIdentity(identity);
2197 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002198 }
2199
2200 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002201 public String getTypeAllocationCodeForSlot(int slotIndex) {
2202 Phone phone = PhoneFactory.getPhone(slotIndex);
2203 String tac = null;
2204 if (phone != null) {
2205 String imei = phone.getImei();
2206 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2207 }
2208 return tac;
2209 }
2210
2211 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002212 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002213 Phone phone = PhoneFactory.getPhone(slotIndex);
2214 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002215 return null;
2216 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002217
Jeff Davidson913390f2018-02-23 17:11:49 -08002218 int subId = phone.getSubId();
2219 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2220 mApp, subId, callingPackage, "getMeidForSlot")) {
2221 return null;
2222 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002223
2224 final long identity = Binder.clearCallingIdentity();
2225 try {
2226 return phone.getMeid();
2227 } finally {
2228 Binder.restoreCallingIdentity(identity);
2229 }
Jack Yu2af8d712017-03-15 17:14:14 -07002230 }
2231
2232 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002233 public String getManufacturerCodeForSlot(int slotIndex) {
2234 Phone phone = PhoneFactory.getPhone(slotIndex);
2235 String manufacturerCode = null;
2236 if (phone != null) {
2237 String meid = phone.getMeid();
2238 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2239 }
2240 return manufacturerCode;
2241 }
2242
2243 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002244 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002245 Phone phone = PhoneFactory.getPhone(slotIndex);
2246 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002247 return null;
2248 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002249 int subId = phone.getSubId();
2250 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2251 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2252 return null;
2253 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002254
2255 final long identity = Binder.clearCallingIdentity();
2256 try {
2257 return phone.getDeviceSvn();
2258 } finally {
2259 Binder.restoreCallingIdentity(identity);
2260 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002261 }
2262
fionaxu43304da2017-11-27 22:51:16 -08002263 @Override
2264 public int getSubscriptionCarrierId(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002265 final long identity = Binder.clearCallingIdentity();
2266 try {
2267 final Phone phone = getPhone(subId);
2268 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2269 } finally {
2270 Binder.restoreCallingIdentity(identity);
2271 }
fionaxu43304da2017-11-27 22:51:16 -08002272 }
2273
2274 @Override
2275 public String getSubscriptionCarrierName(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002276 final long identity = Binder.clearCallingIdentity();
2277 try {
2278 final Phone phone = getPhone(subId);
2279 return phone == null ? null : phone.getCarrierName();
2280 } finally {
2281 Binder.restoreCallingIdentity(identity);
2282 }
fionaxu43304da2017-11-27 22:51:16 -08002283 }
2284
calvinpaneed9ae82018-11-01 19:43:06 +08002285 @Override
chen xua31f22b2019-03-06 15:28:50 -08002286 public int getSubscriptionSpecificCarrierId(int subId) {
chen xuc93cc282018-11-04 17:17:00 -08002287 final long identity = Binder.clearCallingIdentity();
2288 try {
2289 final Phone phone = getPhone(subId);
2290 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xua31f22b2019-03-06 15:28:50 -08002291 : phone.getSpecificCarrierId();
chen xuc93cc282018-11-04 17:17:00 -08002292 } finally {
2293 Binder.restoreCallingIdentity(identity);
2294 }
2295 }
2296
2297 @Override
chen xua31f22b2019-03-06 15:28:50 -08002298 public String getSubscriptionSpecificCarrierName(int subId) {
chen xuc93cc282018-11-04 17:17:00 -08002299 final long identity = Binder.clearCallingIdentity();
2300 try {
2301 final Phone phone = getPhone(subId);
chen xua31f22b2019-03-06 15:28:50 -08002302 return phone == null ? null : phone.getSpecificCarrierName();
chen xuc93cc282018-11-04 17:17:00 -08002303 } finally {
2304 Binder.restoreCallingIdentity(identity);
2305 }
2306 }
2307
chen xu02581692018-11-11 19:03:44 -08002308 @Override
chen xu4ca4e692018-12-06 22:10:03 -08002309 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2310 if (!isSubscriptionMccMnc) {
2311 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2312 }
chen xu02581692018-11-11 19:03:44 -08002313 final Phone phone = PhoneFactory.getPhone(slotIndex);
2314 if (phone == null) {
2315 return TelephonyManager.UNKNOWN_CARRIER_ID;
2316 }
2317 final long identity = Binder.clearCallingIdentity();
2318 try {
2319 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2320 } finally {
2321 Binder.restoreCallingIdentity(identity);
2322 }
2323 }
2324
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002325 //
2326 // Internal helper methods.
2327 //
2328
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002329 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002330 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2331 *
2332 * @throws SecurityException if the caller does not have the required permission
2333 */
2334 private void enforceModifyPermission() {
2335 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2336 }
2337
2338 /**
2339 * Make sure the caller has the CALL_PHONE permission.
2340 *
2341 * @throws SecurityException if the caller does not have the required permission
2342 */
2343 private void enforceCallPermission() {
2344 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2345 }
2346
Stuart Scott8eef64f2015-04-08 15:13:54 -07002347 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002348 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002349 "ConnectivityService");
2350 }
2351
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002352 private String createTelUrl(String number) {
2353 if (TextUtils.isEmpty(number)) {
2354 return null;
2355 }
2356
Jake Hambye994d462014-02-03 13:10:13 -08002357 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002358 }
2359
Ihab Awadf9e92732013-12-05 18:02:52 -08002360 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002361 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2362 }
2363
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002364 private static void logv(String msg) {
2365 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2366 }
2367
Ihab Awadf9e92732013-12-05 18:02:52 -08002368 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002369 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2370 }
2371
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002372 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002373 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002374 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002375 }
2376
Sanket Padawe356d7632015-06-22 14:03:32 -07002377 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002378 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002379 final long identity = Binder.clearCallingIdentity();
2380 try {
2381 final Phone phone = PhoneFactory.getPhone(slotIndex);
2382 if (phone == null) {
2383 return PhoneConstants.PHONE_TYPE_NONE;
2384 } else {
2385 return phone.getPhoneType();
2386 }
2387 } finally {
2388 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002389 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002390 }
2391
2392 /**
2393 * Returns the CDMA ERI icon index to display
2394 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002395 @Override
2396 public int getCdmaEriIconIndex(String callingPackage) {
2397 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002398 }
2399
Sanket Padawe356d7632015-06-22 14:03:32 -07002400 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002401 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002402 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002403 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002404 return -1;
2405 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002406
2407 final long identity = Binder.clearCallingIdentity();
2408 try {
2409 final Phone phone = getPhone(subId);
2410 if (phone != null) {
2411 return phone.getCdmaEriIconIndex();
2412 } else {
2413 return -1;
2414 }
2415 } finally {
2416 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002417 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002418 }
2419
2420 /**
2421 * Returns the CDMA ERI icon mode,
2422 * 0 - ON
2423 * 1 - FLASHING
2424 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002425 @Override
2426 public int getCdmaEriIconMode(String callingPackage) {
2427 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002428 }
2429
Sanket Padawe356d7632015-06-22 14:03:32 -07002430 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002431 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002432 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002433 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002434 return -1;
2435 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002436
2437 final long identity = Binder.clearCallingIdentity();
2438 try {
2439 final Phone phone = getPhone(subId);
2440 if (phone != null) {
2441 return phone.getCdmaEriIconMode();
2442 } else {
2443 return -1;
2444 }
2445 } finally {
2446 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002447 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002448 }
2449
2450 /**
2451 * Returns the CDMA ERI text,
2452 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002453 @Override
2454 public String getCdmaEriText(String callingPackage) {
2455 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002456 }
2457
Sanket Padawe356d7632015-06-22 14:03:32 -07002458 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002459 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002460 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002461 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002462 return null;
2463 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002464
2465 final long identity = Binder.clearCallingIdentity();
2466 try {
2467 final Phone phone = getPhone(subId);
2468 if (phone != null) {
2469 return phone.getCdmaEriText();
2470 } else {
2471 return null;
2472 }
2473 } finally {
2474 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002475 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002476 }
2477
2478 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002479 * Returns the CDMA MDN.
2480 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002481 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002482 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002483 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2484 mApp, subId, "getCdmaMdn");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002485
2486 final long identity = Binder.clearCallingIdentity();
2487 try {
2488 final Phone phone = getPhone(subId);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002489 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002490 return phone.getLine1Number();
2491 } else {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002492 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002493 return null;
2494 }
2495 } finally {
2496 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002497 }
2498 }
2499
2500 /**
2501 * Returns the CDMA MIN.
2502 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002503 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002504 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002505 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2506 mApp, subId, "getCdmaMin");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002507
2508 final long identity = Binder.clearCallingIdentity();
2509 try {
2510 final Phone phone = getPhone(subId);
2511 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2512 return phone.getCdmaMin();
2513 } else {
2514 return null;
2515 }
2516 } finally {
2517 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002518 }
2519 }
2520
Hall Liud892bec2018-11-30 14:51:45 -08002521 @Override
2522 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2523 INumberVerificationCallback callback, String callingPackage) {
2524 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2525 != PERMISSION_GRANTED) {
2526 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2527 }
2528 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2529
2530 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2531 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2532 throw new SecurityException("Calling package must be configured in the device config");
2533 }
2534
2535 if (range == null) {
2536 throw new NullPointerException("Range must be non-null");
2537 }
2538
2539 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002540 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002541
2542 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2543 }
2544
Junda Liuca05d5d2014-08-14 22:36:34 -07002545 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002546 * Returns true if CDMA provisioning needs to run.
2547 */
2548 public boolean needsOtaServiceProvisioning() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002549 final long identity = Binder.clearCallingIdentity();
2550 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002551 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chend965c8b2018-02-28 15:00:40 -08002552 } finally {
2553 Binder.restoreCallingIdentity(identity);
2554 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002555 }
2556
2557 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002558 * Sets the voice mail number of a given subId.
2559 */
2560 @Override
2561 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002562 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002563
2564 final long identity = Binder.clearCallingIdentity();
2565 try {
2566 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2567 new Pair<String, String>(alphaTag, number), new Integer(subId));
2568 return success;
2569 } finally {
2570 Binder.restoreCallingIdentity(identity);
2571 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002572 }
2573
Ta-wei Yen87c49842016-05-13 21:19:52 -07002574 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002575 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2576 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002577 String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002578 if (!TextUtils.equals(callingPackage, systemDialer)) {
2579 throw new SecurityException("caller must be system dialer");
2580 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002581
2582 final long identity = Binder.clearCallingIdentity();
2583 try {
2584 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2585 if (phoneAccountHandle == null) {
2586 return null;
2587 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002588 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002589 } finally {
2590 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002591 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002592 }
2593
2594 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002595 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002596 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002597 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002598 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002599 return null;
2600 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002601
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002602 final long identity = Binder.clearCallingIdentity();
2603 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002604 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002605 } finally {
2606 Binder.restoreCallingIdentity(identity);
2607 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002608 }
2609
2610 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002611 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2612 VisualVoicemailSmsFilterSettings settings) {
2613 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002614
2615 final long identity = Binder.clearCallingIdentity();
2616 try {
2617 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002618 mApp, callingPackage, subId, settings);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002619 } finally {
2620 Binder.restoreCallingIdentity(identity);
2621 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002622 }
2623
2624 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002625 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2626 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002627
2628 final long identity = Binder.clearCallingIdentity();
2629 try {
2630 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002631 mApp, callingPackage, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002632 } finally {
2633 Binder.restoreCallingIdentity(identity);
2634 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002635 }
2636
2637 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002638 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2639 String callingPackage, int subId) {
2640 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002641
2642 final long identity = Binder.clearCallingIdentity();
2643 try {
2644 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002645 mApp, callingPackage, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002646 } finally {
2647 Binder.restoreCallingIdentity(identity);
2648 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002649 }
2650
2651 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002652 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002653 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002654
2655 final long identity = Binder.clearCallingIdentity();
2656 try {
2657 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002658 mApp, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002659 } finally {
2660 Binder.restoreCallingIdentity(identity);
2661 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002662 }
2663
2664 @Override
2665 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2666 String number, int port, String text, PendingIntent sentIntent) {
2667 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002668 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002669 enforceSendSmsPermission();
Amit Mahajan716e76c2019-05-13 13:48:32 -07002670 SmsController smsController = PhoneFactory.getSmsController();
2671 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
2672 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002673 }
Amit Mahajan716e76c2019-05-13 13:48:32 -07002674
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002675 /**
fionaxu0152e512016-11-14 13:36:14 -08002676 * Sets the voice activation state of a given subId.
2677 */
2678 @Override
2679 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002680 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2681 mApp, subId, "setVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002682
2683 final long identity = Binder.clearCallingIdentity();
2684 try {
2685 final Phone phone = getPhone(subId);
2686 if (phone != null) {
2687 phone.setVoiceActivationState(activationState);
2688 } else {
2689 loge("setVoiceActivationState fails with invalid subId: " + subId);
2690 }
2691 } finally {
2692 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002693 }
2694 }
2695
2696 /**
2697 * Sets the data activation state of a given subId.
2698 */
2699 @Override
2700 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002701 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2702 mApp, subId, "setDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002703
2704 final long identity = Binder.clearCallingIdentity();
2705 try {
2706 final Phone phone = getPhone(subId);
2707 if (phone != null) {
2708 phone.setDataActivationState(activationState);
2709 } else {
2710 loge("setVoiceActivationState fails with invalid subId: " + subId);
2711 }
2712 } finally {
2713 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002714 }
2715 }
2716
2717 /**
2718 * Returns the voice activation state of a given subId.
2719 */
2720 @Override
2721 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002722 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002723
fionaxu0152e512016-11-14 13:36:14 -08002724 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002725 final long identity = Binder.clearCallingIdentity();
2726 try {
2727 if (phone != null) {
2728 return phone.getVoiceActivationState();
2729 } else {
2730 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2731 }
2732 } finally {
2733 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002734 }
2735 }
2736
2737 /**
2738 * Returns the data activation state of a given subId.
2739 */
2740 @Override
2741 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002742 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002743
fionaxu0152e512016-11-14 13:36:14 -08002744 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002745 final long identity = Binder.clearCallingIdentity();
2746 try {
2747 if (phone != null) {
2748 return phone.getDataActivationState();
2749 } else {
2750 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2751 }
2752 } finally {
2753 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002754 }
2755 }
2756
2757 /**
Wink Saville36469e72014-06-11 15:17:00 -07002758 * Returns the unread count of voicemails for a subId
2759 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002760 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002761 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2762 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2763 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2764 return 0;
2765 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002766 final long identity = Binder.clearCallingIdentity();
2767 try {
2768 final Phone phone = getPhone(subId);
2769 if (phone != null) {
2770 return phone.getVoiceMessageCount();
2771 } else {
2772 return 0;
2773 }
2774 } finally {
2775 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002776 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002777 }
2778
2779 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002780 * returns true, if the device is in a state where both voice and data
2781 * are supported simultaneously. This can change based on location or network condition.
2782 */
2783 @Override
2784 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002785 final long identity = Binder.clearCallingIdentity();
2786 try {
2787 final Phone phone = getPhone(subId);
2788 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2789 } finally {
2790 Binder.restoreCallingIdentity(identity);
2791 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002792 }
2793
2794 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002795 * Send the dialer code if called from the current default dialer or the caller has
2796 * carrier privilege.
2797 * @param inputCode The dialer code to send
2798 */
2799 @Override
2800 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002801 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002802 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002803 String defaultDialer = TelecomManager.from(defaultPhone.getContext())
2804 .getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002805 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002806 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2807 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002808 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002809
2810 final long identity = Binder.clearCallingIdentity();
2811 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002812 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002813 } finally {
2814 Binder.restoreCallingIdentity(identity);
2815 }
fionaxu235cc5e2017-03-06 22:25:57 -08002816 }
2817
Pengquan Meng0c05b502018-09-06 09:59:22 -07002818 @Override
2819 public int getNetworkSelectionMode(int subId) {
Pengquan Meng466e2482018-09-21 15:54:48 -07002820 if (!isActiveSubscription(subId)) {
2821 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2822 }
2823
Pengquan Meng0c05b502018-09-06 09:59:22 -07002824 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2825 }
2826
Brad Ebinger4c460712018-10-01 10:40:55 -07002827 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002828 public boolean isInEmergencySmsMode() {
2829 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2830 final long identity = Binder.clearCallingIdentity();
2831 try {
2832 for (Phone phone : PhoneFactory.getPhones()) {
2833 if (phone.isInEmergencySmsMode()) {
2834 return true;
2835 }
2836 }
2837 } finally {
2838 Binder.restoreCallingIdentity(identity);
2839 }
2840 return false;
2841 }
2842
2843 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002844 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2845 throws RemoteException {
2846 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002847 final long token = Binder.clearCallingIdentity();
2848 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002849 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002850 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002851 .addRegistrationCallbackForSubscription(c, subId);
2852 } finally {
2853 Binder.restoreCallingIdentity(token);
2854 }
2855 }
2856
2857 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002858 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2859 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002860 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2861 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2862 }
2863 Binder.withCleanCallingIdentity(() -> {
2864 try {
2865 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002866 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002867 .removeRegistrationCallbackForSubscription(c, subId);
2868 } catch (IllegalArgumentException e) {
2869 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2870 + "is inactive, ignoring unregister.");
2871 // If the subscription is no longer active, just return, since the callback
2872 // will already have been removed internally.
2873 }
2874 });
Brad Ebinger4c460712018-10-01 10:40:55 -07002875 }
2876
2877 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002878 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2879 throws RemoteException {
2880 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002881 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2882 final long token = Binder.clearCallingIdentity();
2883 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002884 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002885 .addCapabilitiesCallbackForSubscription(c, subId);
2886 } finally {
2887 Binder.restoreCallingIdentity(token);
2888 }
2889 }
2890
2891 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002892 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2893 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002894
2895 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2896 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2897 }
2898 Binder.withCleanCallingIdentity(() -> {
2899 try {
2900 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002901 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002902 .removeCapabilitiesCallbackForSubscription(c, subId);
2903 } catch (IllegalArgumentException e) {
2904 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
2905 + "is inactive, ignoring unregister.");
2906 // If the subscription is no longer active, just return, since the callback
2907 // will already have been removed internally.
2908 }
2909 });
Brad Ebinger4c460712018-10-01 10:40:55 -07002910 }
2911
2912 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002913 public boolean isCapable(int subId, int capability, int regTech) {
2914 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002915 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2916 final long token = Binder.clearCallingIdentity();
2917 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002918 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002919 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2920 } catch (ImsException e) {
2921 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2922 return false;
Brad Ebinger6b5ac222019-02-04 14:36:52 -08002923 } catch (IllegalArgumentException e) {
2924 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
2925 return false;
Brad Ebinger4c460712018-10-01 10:40:55 -07002926 } finally {
2927 Binder.restoreCallingIdentity(token);
2928 }
2929 }
2930
2931 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002932 public boolean isAvailable(int subId, int capability, int regTech) {
2933 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002934 final long token = Binder.clearCallingIdentity();
2935 try {
2936 Phone phone = getPhone(subId);
2937 if (phone == null) return false;
2938 return phone.isImsCapabilityAvailable(capability, regTech);
2939 } finally {
2940 Binder.restoreCallingIdentity(token);
2941 }
2942 }
2943
2944 @Override
2945 public boolean isAdvancedCallingSettingEnabled(int subId) {
2946 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2947 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2948 final long token = Binder.clearCallingIdentity();
2949 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002950 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002951 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2952 } finally {
2953 Binder.restoreCallingIdentity(token);
2954 }
2955 }
2956
2957 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08002958 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002959 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08002960 "setAdvancedCallingSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002961 final long identity = Binder.clearCallingIdentity();
2962 try {
2963 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002964 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002965 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2966 } finally {
2967 Binder.restoreCallingIdentity(identity);
2968 }
2969 }
2970
2971 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002972 public boolean isVtSettingEnabled(int subId) {
2973 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002974 final long identity = Binder.clearCallingIdentity();
2975 try {
2976 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002977 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002978 getSlotIndexOrException(subId)).isVtEnabledByUser();
2979 } finally {
2980 Binder.restoreCallingIdentity(identity);
2981 }
2982 }
2983
2984 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08002985 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002986 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08002987 "setVtSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002988 final long identity = Binder.clearCallingIdentity();
2989 try {
2990 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002991 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger4c460712018-10-01 10:40:55 -07002992 } finally {
2993 Binder.restoreCallingIdentity(identity);
2994 }
2995 }
2996
2997 @Override
2998 public boolean isVoWiFiSettingEnabled(int subId) {
2999 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3000 final long identity = Binder.clearCallingIdentity();
3001 try {
3002 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003003 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003004 getSlotIndexOrException(subId)).isWfcEnabledByUser();
3005 } finally {
3006 Binder.restoreCallingIdentity(identity);
3007 }
3008 }
3009
3010 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08003011 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07003012 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08003013 "setVoWiFiSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07003014 final long identity = Binder.clearCallingIdentity();
3015 try {
3016 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003017 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger4c460712018-10-01 10:40:55 -07003018 } finally {
3019 Binder.restoreCallingIdentity(identity);
3020 }
3021 }
3022
3023 @Override
3024 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3025 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3026 final long identity = Binder.clearCallingIdentity();
3027 try {
3028 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003029 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003030 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
3031 } finally {
3032 Binder.restoreCallingIdentity(identity);
3033 }
3034 }
3035
3036 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08003037 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07003038 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08003039 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07003040 final long identity = Binder.clearCallingIdentity();
3041 try {
3042 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003043 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003044 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
3045 } finally {
3046 Binder.restoreCallingIdentity(identity);
3047 }
3048 }
3049
3050 @Override
3051 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3052 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3053 "setVoWiFiNonPersistent");
3054 final long identity = Binder.clearCallingIdentity();
3055 try {
3056 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003057 ImsManager.getInstance(mApp,
Brad Ebinger2bc95702019-05-07 18:33:46 -07003058 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger4c460712018-10-01 10:40:55 -07003059 } finally {
3060 Binder.restoreCallingIdentity(identity);
3061 }
3062 }
3063
3064 @Override
3065 public int getVoWiFiModeSetting(int subId) {
3066 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3067 final long identity = Binder.clearCallingIdentity();
3068 try {
3069 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003070 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003071 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
3072 } finally {
3073 Binder.restoreCallingIdentity(identity);
3074 }
3075 }
3076
3077 @Override
3078 public void setVoWiFiModeSetting(int subId, int mode) {
3079 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3080 "setVoWiFiModeSetting");
3081 final long identity = Binder.clearCallingIdentity();
3082 try {
3083 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003084 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003085 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
3086 } finally {
3087 Binder.restoreCallingIdentity(identity);
3088 }
3089 }
3090
3091 @Override
3092 public int getVoWiFiRoamingModeSetting(int subId) {
3093 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3094 final long identity = Binder.clearCallingIdentity();
3095 try {
3096 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003097 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003098 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
3099 } finally {
3100 Binder.restoreCallingIdentity(identity);
3101 }
3102 }
3103
3104 @Override
3105 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3106 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3107 "setVoWiFiRoamingModeSetting");
3108 final long identity = Binder.clearCallingIdentity();
3109 try {
3110 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003111 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003112 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
3113 } finally {
3114 Binder.restoreCallingIdentity(identity);
3115 }
3116 }
3117
3118 @Override
3119 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3120 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3121 "setRttCapabilityEnabled");
3122 final long identity = Binder.clearCallingIdentity();
3123 try {
3124 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003125 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003126 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3127 } finally {
3128 Binder.restoreCallingIdentity(identity);
3129 }
3130 }
3131
3132 @Override
3133 public boolean isTtyOverVolteEnabled(int subId) {
3134 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3135 final long identity = Binder.clearCallingIdentity();
3136 try {
3137 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003138 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003139 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
3140 } finally {
3141 Binder.restoreCallingIdentity(identity);
3142 }
3143 }
3144
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003145 @Override
3146 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3147 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3148 final long identity = Binder.clearCallingIdentity();
3149 try {
3150 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003151 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003152 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003153 } finally {
3154 Binder.restoreCallingIdentity(identity);
3155 }
3156 }
3157
3158 @Override
3159 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3160 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3161 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003162 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3163 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3164 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003165 try {
3166 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003167 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003168 .removeProvisioningCallbackForSubscription(callback, subId);
3169 } catch (IllegalArgumentException e) {
3170 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3171 + "is inactive, ignoring unregister.");
3172 // If the subscription is no longer active, just return, since the callback will already
3173 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003174 } finally {
3175 Binder.restoreCallingIdentity(identity);
3176 }
3177 }
3178
3179 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003180 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3181 boolean isProvisioned) {
3182 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3183 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3184 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3185 }
3186 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3187 "setProvisioningStatusForCapability");
3188 final long identity = Binder.clearCallingIdentity();
3189 try {
3190 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3191 Phone phone = getPhone(subId);
3192 if (phone == null) {
3193 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3194 + subId);
3195 return;
3196 }
3197 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3198 return;
3199 }
3200
3201 // this capability requires provisioning, route to the correct API.
3202 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3203 switch (capability) {
3204 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3205 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3206 ims.setVolteProvisioned(isProvisioned);
3207 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3208 ims.setWfcProvisioned(isProvisioned);
3209 }
3210 break;
3211 }
3212 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3213 // There is currently no difference in VT provisioning type.
3214 ims.setVtProvisioned(isProvisioned);
3215 break;
3216 }
3217 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3218 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3219 // change the capability of the feature instead if needed.
3220 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3221 == isProvisioned) {
3222 // No change in provisioning.
3223 return;
3224 }
3225 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3226 try {
3227 ims.changeMmTelCapability(capability, tech, isProvisioned);
3228 } catch (ImsException e) {
3229 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3230 + ", Exception" + e.getMessage());
3231 }
3232 break;
3233 }
3234 default: {
3235 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3236 + capability + "', which does not require provisioning.");
3237 }
3238 }
3239
3240 } finally {
3241 Binder.restoreCallingIdentity(identity);
3242 }
3243 }
3244
3245 @Override
3246 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3247 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3248 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3249 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3250 }
3251 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3252 final long identity = Binder.clearCallingIdentity();
3253 try {
3254 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3255 Phone phone = getPhone(subId);
3256 if (phone == null) {
3257 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3258 + subId);
3259 // We will fail with "true" as the provisioning status because this is the default
3260 // if we do not require provisioning.
3261 return true;
3262 }
3263
3264 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3265 return true;
3266 }
3267
3268 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3269 switch (capability) {
3270 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3271 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3272 return ims.isVolteProvisionedOnDevice();
3273 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3274 return ims.isWfcProvisionedOnDevice();
3275 }
3276 // This should never happen, since we are checking tech above to make sure it
3277 // is either LTE or IWLAN.
3278 throw new IllegalArgumentException("Invalid radio technology for voice "
3279 + "capability.");
3280 }
3281 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3282 // There is currently no difference in VT provisioning type.
3283 return ims.isVtProvisionedOnDevice();
3284 }
3285 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3286 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3287 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3288 }
3289 default: {
3290 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3291 + capability + "', which does not require provisioning.");
3292 }
3293 }
3294
3295 } finally {
3296 Binder.restoreCallingIdentity(identity);
3297 }
3298 }
3299
3300 @Override
3301 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3302 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3303 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3304 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3305 }
3306 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3307 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3308 return (provisionedBits & capability) > 0;
3309 }
3310
3311 @Override
3312 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3313 boolean isProvisioned) {
3314 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3315 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3316 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3317 }
3318 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3319 "setProvisioningStatusForCapability");
3320 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3321 // If the current provisioning status for capability already matches isProvisioned,
3322 // do nothing.
3323 if (((provisionedBits & capability) > 0) == isProvisioned) {
3324 return;
3325 }
3326 if (isProvisioned) {
3327 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3328 } else {
3329 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3330 }
3331 }
3332
3333 /**
3334 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3335 * technology. The bitfield should mirror the bitfield defined by
3336 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3337 */
3338 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3339 String key = getMmTelProvisioningKey(subId, tech);
3340 // Default is no capabilities are provisioned.
3341 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3342 }
3343
3344 /**
3345 * Sets the MmTel capability provisioning bitfield (defined by
3346 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3347 * technology specified.
3348 *
3349 * Note: This is a synchronous command and should not be called on UI thread.
3350 */
3351 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3352 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3353 String key = getMmTelProvisioningKey(subId, tech);
3354 editor.putInt(key, newField);
3355 editor.commit();
3356 }
3357
3358 private static String getMmTelProvisioningKey(int subId, int tech) {
3359 // resulting key is provision_ims_mmtel_{subId}_{tech}
3360 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3361 }
3362
3363 /**
3364 * Query CarrierConfig to see if the specified capability requires provisioning for the
3365 * carrier associated with the subscription id.
3366 */
3367 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3368 int capability) {
3369 CarrierConfigManager configManager = new CarrierConfigManager(context);
3370 PersistableBundle c = configManager.getConfigForSubId(subId);
3371 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07003372 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003373 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3374 false);
3375 boolean requireVoiceVtProvisioning = c.getBoolean(
3376 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3377
3378 // First check to make sure that the capability requires provisioning.
3379 switch (capability) {
3380 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3381 // intentional fallthrough
3382 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3383 if (requireVoiceVtProvisioning) {
3384 // Voice and Video requires provisioning
3385 return true;
3386 }
3387 break;
3388 }
3389 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3390 if (requireUtProvisioning) {
3391 // UT requires provisioning
3392 return true;
3393 }
3394 break;
3395 }
3396 }
3397 return false;
3398 }
3399
3400 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003401 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003402 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3403 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3404 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003405 enforceReadPrivilegedPermission("getImsProvisioningInt");
3406 final long identity = Binder.clearCallingIdentity();
3407 try {
3408 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003409 int slotId = getSlotIndex(subId);
3410 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3411 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3412 + subId + "' for key:" + key);
3413 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3414 }
3415 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003416 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003417 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3418 + subId + "' for key:" + key);
3419 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003420 } finally {
3421 Binder.restoreCallingIdentity(identity);
3422 }
3423 }
3424
3425 @Override
3426 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003427 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3428 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3429 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003430 enforceReadPrivilegedPermission("getImsProvisioningString");
3431 final long identity = Binder.clearCallingIdentity();
3432 try {
3433 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003434 int slotId = getSlotIndex(subId);
3435 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3436 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3437 + subId + "' for key:" + key);
3438 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3439 }
3440 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003441 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003442 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3443 + subId + "' for key:" + key);
3444 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003445 } finally {
3446 Binder.restoreCallingIdentity(identity);
3447 }
3448 }
3449
3450 @Override
3451 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003452 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3453 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3454 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003455 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3456 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003457 final long identity = Binder.clearCallingIdentity();
3458 try {
3459 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003460 int slotId = getSlotIndex(subId);
3461 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3462 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3463 + subId + "' for key:" + key);
3464 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3465 }
3466 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003467 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003468 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3469 + "' for key:" + key);
3470 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003471 } finally {
3472 Binder.restoreCallingIdentity(identity);
3473 }
3474 }
3475
3476 @Override
3477 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003478 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3479 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3480 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003481 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3482 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003483 final long identity = Binder.clearCallingIdentity();
3484 try {
3485 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003486 int slotId = getSlotIndex(subId);
3487 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3488 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3489 + subId + "' for key:" + key);
3490 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3491 }
3492 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003493 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003494 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3495 + "' for key:" + key);
3496 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003497 } finally {
3498 Binder.restoreCallingIdentity(identity);
3499 }
3500 }
3501
Brad Ebinger4c460712018-10-01 10:40:55 -07003502 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
3503 int slotId = SubscriptionManager.getSlotIndex(subId);
3504 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003505 throw new IllegalArgumentException("Invalid Subscription Id, subId=" + subId);
Brad Ebinger4c460712018-10-01 10:40:55 -07003506 }
3507 return slotId;
3508 }
3509
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003510 private int getSlotIndex(int subId) {
3511 int slotId = SubscriptionManager.getSlotIndex(subId);
3512 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3513 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3514 }
3515 return slotId;
3516 }
3517
Wink Saville36469e72014-06-11 15:17:00 -07003518 /**
Nathan Haroldb3a3a802019-05-21 15:51:27 -07003519 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07003520 */
3521 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003522 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07003523 final int targetSdk = getTargetSdk(callingPackage);
3524 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
3525 return getDataNetworkTypeForSubscriber(subId, callingPackage);
3526 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Haroldb3a3a802019-05-21 15:51:27 -07003527 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
3528 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003529 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3530 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003531
Malcolm Chend965c8b2018-02-28 15:00:40 -08003532 final long identity = Binder.clearCallingIdentity();
3533 try {
3534 final Phone phone = getPhone(subId);
3535 if (phone != null) {
3536 return phone.getServiceState().getDataNetworkType();
3537 } else {
3538 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3539 }
3540 } finally {
3541 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003542 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003543 }
3544
3545 /**
3546 * Returns the data network type
3547 */
3548 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003549 public int getDataNetworkType(String callingPackage) {
3550 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003551 }
3552
3553 /**
3554 * Returns the data network type for a subId
3555 */
3556 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003557 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003558 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003559 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003560 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3561 }
3562
Malcolm Chend965c8b2018-02-28 15:00:40 -08003563 final long identity = Binder.clearCallingIdentity();
3564 try {
3565 final Phone phone = getPhone(subId);
3566 if (phone != null) {
3567 return phone.getServiceState().getDataNetworkType();
3568 } else {
3569 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3570 }
3571 } finally {
3572 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003573 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003574 }
3575
3576 /**
Wink Saville36469e72014-06-11 15:17:00 -07003577 * Returns the Voice network type for a subId
3578 */
3579 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003580 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003581 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003582 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003583 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3584 }
3585
Malcolm Chend965c8b2018-02-28 15:00:40 -08003586 final long identity = Binder.clearCallingIdentity();
3587 try {
3588 final Phone phone = getPhone(subId);
3589 if (phone != null) {
3590 return phone.getServiceState().getVoiceNetworkType();
3591 } else {
3592 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3593 }
3594 } finally {
3595 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003596 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003597 }
3598
3599 /**
3600 * @return true if a ICC card is present
3601 */
3602 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003603 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003604 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3605 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003606 }
3607
3608 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003609 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003610 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003611 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003612 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003613 final long identity = Binder.clearCallingIdentity();
3614 try {
3615 final Phone phone = PhoneFactory.getPhone(slotIndex);
3616 if (phone != null) {
3617 return phone.getIccCard().hasIccCard();
3618 } else {
3619 return false;
3620 }
3621 } finally {
3622 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003623 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003624 }
3625
3626 /**
3627 * Return if the current radio is LTE on CDMA. This
3628 * is a tri-state return value as for a period of time
3629 * the mode may be unknown.
3630 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003631 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003632 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003633 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003634 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003635 @Override
3636 public int getLteOnCdmaMode(String callingPackage) {
3637 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003638 }
3639
Sanket Padawe356d7632015-06-22 14:03:32 -07003640 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003641 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003642 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003643 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003644 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3645 }
3646
Malcolm Chend965c8b2018-02-28 15:00:40 -08003647 final long identity = Binder.clearCallingIdentity();
3648 try {
3649 final Phone phone = getPhone(subId);
3650 if (phone == null) {
3651 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3652 } else {
3653 return phone.getLteOnCdmaMode();
3654 }
3655 } finally {
3656 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003657 }
Wink Saville36469e72014-06-11 15:17:00 -07003658 }
3659
Wink Saville36469e72014-06-11 15:17:00 -07003660 /**
3661 * {@hide}
3662 * Returns Default subId, 0 in the case of single standby.
3663 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003664 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003665 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003666 }
3667
Shishir Agrawala9f32182016-04-12 12:00:16 -07003668 private int getSlotForDefaultSubscription() {
3669 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3670 }
3671
Wink Savilleb564aae2014-10-23 10:18:09 -07003672 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003673 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003674 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003675
Pengquan Meng466e2482018-09-21 15:54:48 -07003676 private boolean isActiveSubscription(int subId) {
3677 return mSubscriptionController.isActiveSubId(subId);
3678 }
3679
Ihab Awadf2177b72013-11-25 13:33:23 -08003680 /**
3681 * @see android.telephony.TelephonyManager.WifiCallingChoices
3682 */
3683 public int getWhenToMakeWifiCalls() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003684 final long identity = Binder.clearCallingIdentity();
3685 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003686 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003687 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3688 getWhenToMakeWifiCallsDefaultPreference());
3689 } finally {
3690 Binder.restoreCallingIdentity(identity);
3691 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003692 }
3693
3694 /**
3695 * @see android.telephony.TelephonyManager.WifiCallingChoices
3696 */
3697 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003698 final long identity = Binder.clearCallingIdentity();
3699 try {
3700 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003701 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003702 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3703 } finally {
3704 Binder.restoreCallingIdentity(identity);
3705 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003706 }
3707
Sailesh Nepald1e68152013-12-12 19:08:02 -08003708 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003709 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003710 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003711 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003712
Jordan Liu73b078d2019-02-28 12:03:40 -08003713 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
3714 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
3715 if (phoneId == -1) {
3716 throw new IllegalArgumentException("Given slot index: " + slotIndex
3717 + " does not correspond to an active phone");
3718 }
3719 return PhoneFactory.getPhone(phoneId);
3720 }
3721
Shishir Agrawal566b7612013-10-28 14:41:00 -07003722 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003723 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3724 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003725 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3726 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003727 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu73b078d2019-02-28 12:03:40 -08003728 if (DBG) {
3729 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3730 }
3731 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
3732 p2);
3733 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003734
Jordan Liu73b078d2019-02-28 12:03:40 -08003735
3736 @Override
3737 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
3738 int slotIndex, String callingPackage, String aid, int p2) {
3739 enforceModifyPermission();
3740 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3741 if (DBG) {
3742 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
3743 }
3744 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3745 callingPackage, aid, p2);
3746 }
3747
3748 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
3749 String callingPackage, String aid, int p2) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003750 final long identity = Binder.clearCallingIdentity();
3751 try {
3752 if (TextUtils.equals(ISDR_AID, aid)) {
3753 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003754 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3755 .getContext().getPackageManager());
Malcolm Chend965c8b2018-02-28 15:00:40 -08003756 if (bestComponent == null
3757 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3758 loge("The calling package is not allowed to access ISD-R.");
3759 throw new SecurityException(
3760 "The calling package is not allowed to access ISD-R.");
3761 }
Derek Tan740e1672017-06-27 14:56:27 -07003762 }
Derek Tan740e1672017-06-27 14:56:27 -07003763
Malcolm Chend965c8b2018-02-28 15:00:40 -08003764 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu73b078d2019-02-28 12:03:40 -08003765 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
3766 null /* workSource */);
3767 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003768 return response;
3769 } finally {
3770 Binder.restoreCallingIdentity(identity);
3771 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003772 }
3773
3774 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003775 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003776 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3777 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu73b078d2019-02-28 12:03:40 -08003778 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3779 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
3780 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003781
Jordan Liu73b078d2019-02-28 12:03:40 -08003782 @Override
3783 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
3784 enforceModifyPermission();
3785 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
3786 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3787 channel);
3788 }
3789
3790 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003791 final long identity = Binder.clearCallingIdentity();
3792 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003793 if (channel < 0) {
3794 return false;
3795 }
Jordan Liu73b078d2019-02-28 12:03:40 -08003796 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
3797 null /* workSource */);
3798 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003799 return success;
3800 } finally {
3801 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003802 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003803 }
3804
3805 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003806 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003807 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003808 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3809 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu73b078d2019-02-28 12:03:40 -08003810 if (DBG) {
3811 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3812 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3813 + p3 + " data=" + data);
3814 }
3815 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
3816 command, p1, p2, p3, data);
3817 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003818
Jordan Liu73b078d2019-02-28 12:03:40 -08003819 @Override
3820 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
3821 int command, int p1, int p2, int p3, String data) {
3822 enforceModifyPermission();
3823 if (DBG) {
3824 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
3825 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3826 + p3 + " data=" + data);
3827 }
3828 return iccTransmitApduLogicalChannelWithPermission(
3829 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
3830 data);
3831 }
3832
3833 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
3834 int command, int p1, int p2, int p3, String data) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003835 final long identity = Binder.clearCallingIdentity();
3836 try {
Hall Liucdcfa292019-05-02 09:16:29 -07003837 if (channel <= 0) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003838 return "";
3839 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003840
Malcolm Chend965c8b2018-02-28 15:00:40 -08003841 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu73b078d2019-02-28 12:03:40 -08003842 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
3843 null /* workSource */);
3844 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003845
Malcolm Chend965c8b2018-02-28 15:00:40 -08003846 // Append the returned status code to the end of the response payload.
3847 String s = Integer.toHexString(
3848 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3849 if (response.payload != null) {
3850 s = IccUtils.bytesToHexString(response.payload) + s;
3851 }
3852 return s;
3853 } finally {
3854 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003855 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003856 }
Jake Hambye994d462014-02-03 13:10:13 -08003857
Evan Charltonc66da362014-05-16 14:06:40 -07003858 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003859 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3860 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003861 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3862 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003863 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu73b078d2019-02-28 12:03:40 -08003864 if (DBG) {
3865 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3866 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3867 }
3868 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
3869 cla, command, p1, p2, p3, data);
3870 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003871
Jordan Liu73b078d2019-02-28 12:03:40 -08003872 @Override
3873 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
3874 int command, int p1, int p2, int p3, String data) {
3875 enforceModifyPermission();
3876 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3877 if (DBG) {
3878 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
3879 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
3880 + " data=" + data);
3881 }
3882
3883 return iccTransmitApduBasicChannelWithPermission(
3884 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
3885 p2, p3, data);
3886 }
3887
3888 // open APDU basic channel assuming the caller has sufficient permissions
3889 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
3890 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003891 final long identity = Binder.clearCallingIdentity();
3892 try {
3893 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3894 && TextUtils.equals(ISDR_AID, data)) {
3895 // Only allows LPA to select ISD-R.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003896 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3897 .getContext().getPackageManager());
Malcolm Chend965c8b2018-02-28 15:00:40 -08003898 if (bestComponent == null
3899 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3900 loge("The calling package is not allowed to select ISD-R.");
3901 throw new SecurityException(
3902 "The calling package is not allowed to select ISD-R.");
3903 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003904 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003905
Malcolm Chend965c8b2018-02-28 15:00:40 -08003906 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu73b078d2019-02-28 12:03:40 -08003907 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
3908 null /* workSource */);
3909 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003910
Malcolm Chend965c8b2018-02-28 15:00:40 -08003911 // Append the returned status code to the end of the response payload.
3912 String s = Integer.toHexString(
3913 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3914 if (response.payload != null) {
3915 s = IccUtils.bytesToHexString(response.payload) + s;
3916 }
3917 return s;
3918 } finally {
3919 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003920 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003921 }
3922
3923 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003924 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003925 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003926 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3927 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003928
Malcolm Chend965c8b2018-02-28 15:00:40 -08003929 final long identity = Binder.clearCallingIdentity();
3930 try {
3931 if (DBG) {
3932 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3933 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3934 }
3935
3936 IccIoResult response =
3937 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3938 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3939 subId);
3940
3941 if (DBG) {
3942 log("Exchange SIM_IO [R]" + response);
3943 }
3944
3945 byte[] result = null;
3946 int length = 2;
3947 if (response.payload != null) {
3948 length = 2 + response.payload.length;
3949 result = new byte[length];
3950 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3951 } else {
3952 result = new byte[length];
3953 }
3954
3955 result[length - 1] = (byte) response.sw2;
3956 result[length - 2] = (byte) response.sw1;
3957 return result;
3958 } finally {
3959 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003960 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003961 }
3962
Nathan Haroldb3014052017-01-25 15:57:32 -08003963 /**
3964 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3965 * on a particular subscription
3966 */
sqianb6e41952018-03-12 14:54:01 -07003967 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3968 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3969 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3970 return null;
3971 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003972
3973 final long identity = Binder.clearCallingIdentity();
3974 try {
3975 if (appType != TelephonyManager.APPTYPE_USIM
3976 && appType != TelephonyManager.APPTYPE_SIM) {
3977 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3978 return null;
3979 }
3980 Object response = sendRequest(
3981 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3982 if (response instanceof String[]) {
3983 return (String[]) response;
3984 }
3985 // Response is an Exception of some kind,
3986 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003987 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08003988 } finally {
3989 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003990 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003991 }
3992
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003993 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003994 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003995 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3996 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003997
Malcolm Chend965c8b2018-02-28 15:00:40 -08003998 final long identity = Binder.clearCallingIdentity();
3999 try {
4000 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4001 if (response.payload == null) {
4002 return "";
4003 }
Evan Charltonc66da362014-05-16 14:06:40 -07004004
Malcolm Chend965c8b2018-02-28 15:00:40 -08004005 // Append the returned status code to the end of the response payload.
4006 String s = Integer.toHexString(
4007 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4008 s = IccUtils.bytesToHexString(response.payload) + s;
4009 return s;
4010 } finally {
4011 Binder.restoreCallingIdentity(identity);
4012 }
Evan Charltonc66da362014-05-16 14:06:40 -07004013 }
4014
Jake Hambye994d462014-02-03 13:10:13 -08004015 /**
4016 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4017 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4018 *
4019 * @param itemID the ID of the item to read
4020 * @return the NV item as a String, or null on error.
4021 */
4022 @Override
4023 public String nvReadItem(int itemID) {
vagdevie435a3e2018-08-15 16:01:53 -07004024 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004025 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4026 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004027
4028 final long identity = Binder.clearCallingIdentity();
4029 try {
4030 if (DBG) log("nvReadItem: item " + itemID);
vagdevie435a3e2018-08-15 16:01:53 -07004031 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004032 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4033 return value;
4034 } finally {
4035 Binder.restoreCallingIdentity(identity);
4036 }
Jake Hambye994d462014-02-03 13:10:13 -08004037 }
4038
4039 /**
4040 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4041 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4042 *
4043 * @param itemID the ID of the item to read
4044 * @param itemValue the value to write, as a String
4045 * @return true on success; false on any failure
4046 */
4047 @Override
4048 public boolean nvWriteItem(int itemID, String itemValue) {
vagdevie435a3e2018-08-15 16:01:53 -07004049 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004050 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4051 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004052
4053 final long identity = Binder.clearCallingIdentity();
4054 try {
4055 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4056 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdevie435a3e2018-08-15 16:01:53 -07004057 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004058 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4059 return success;
4060 } finally {
4061 Binder.restoreCallingIdentity(identity);
4062 }
Jake Hambye994d462014-02-03 13:10:13 -08004063 }
4064
4065 /**
4066 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4067 * Used for device configuration by some CDMA operators.
4068 *
4069 * @param preferredRoamingList byte array containing the new PRL
4070 * @return true on success; false on any failure
4071 */
4072 @Override
4073 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004074 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4075 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004076
4077 final long identity = Binder.clearCallingIdentity();
4078 try {
4079 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4080 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4081 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4082 return success;
4083 } finally {
4084 Binder.restoreCallingIdentity(identity);
4085 }
Jake Hambye994d462014-02-03 13:10:13 -08004086 }
4087
4088 /**
chen xu1cc0abe2018-10-26 17:39:23 -07004089 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004090 * Used for device configuration by some CDMA operators.
4091 *
chen xu1cc0abe2018-10-26 17:39:23 -07004092 * @param slotIndex - device slot.
4093 *
Jake Hambye994d462014-02-03 13:10:13 -08004094 * @return true on success; false on any failure
4095 */
4096 @Override
chen xu1cc0abe2018-10-26 17:39:23 -07004097 public boolean resetModemConfig(int slotIndex) {
4098 Phone phone = PhoneFactory.getPhone(slotIndex);
4099 if (phone != null) {
4100 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4101 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004102
chen xu1cc0abe2018-10-26 17:39:23 -07004103 final long identity = Binder.clearCallingIdentity();
4104 try {
4105 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4106 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4107 return success;
4108 } finally {
4109 Binder.restoreCallingIdentity(identity);
4110 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004111 }
chen xu1cc0abe2018-10-26 17:39:23 -07004112 return false;
4113 }
4114
4115 /**
4116 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4117 *
4118 * @param slotIndex - device slot.
4119 *
4120 * @return true on success; false on any failure
4121 */
4122 @Override
4123 public boolean rebootModem(int slotIndex) {
4124 Phone phone = PhoneFactory.getPhone(slotIndex);
4125 if (phone != null) {
4126 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4127 mApp, phone.getSubId(), "rebootModem");
4128
4129 final long identity = Binder.clearCallingIdentity();
4130 try {
4131 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4132 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4133 return success;
4134 } finally {
4135 Binder.restoreCallingIdentity(identity);
4136 }
4137 }
4138 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004139 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004140
Svet Ganovb320e182015-04-16 12:30:10 -07004141 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004142 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004143 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004144 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004145 return new String[0];
4146 }
4147
Malcolm Chend965c8b2018-02-28 15:00:40 -08004148 final long identity = Binder.clearCallingIdentity();
4149 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004150 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004151 } finally {
4152 Binder.restoreCallingIdentity(identity);
4153 }
Wink Saville36469e72014-06-11 15:17:00 -07004154 }
4155
Brad Ebinger51f743a2017-01-23 13:50:20 -08004156 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004157 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4158 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004159 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004160 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004161 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004162
4163 final long identity = Binder.clearCallingIdentity();
4164 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004165 ImsResolver resolver = PhoneFactory.getImsResolver();
4166 if (resolver == null) {
4167 // may happen if the device does not support IMS.
4168 return;
4169 }
4170 resolver.enableIms(slotId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004171 } finally {
4172 Binder.restoreCallingIdentity(identity);
4173 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004174 }
4175
4176 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004177 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4178 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004179 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004180 public void disableIms(int slotId) {
4181 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004182
4183 final long identity = Binder.clearCallingIdentity();
4184 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004185 ImsResolver resolver = PhoneFactory.getImsResolver();
4186 if (resolver == null) {
4187 // may happen if the device does not support IMS.
4188 return;
4189 }
4190 resolver.disableIms(slotId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004191 } finally {
4192 Binder.restoreCallingIdentity(identity);
4193 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004194 }
4195
4196 /**
4197 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4198 * feature or {@link null} if the service is not available. If the feature is available, the
4199 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4200 */
4201 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004202 IImsServiceFeatureCallback callback) {
4203 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004204
4205 final long identity = Binder.clearCallingIdentity();
4206 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004207 ImsResolver resolver = PhoneFactory.getImsResolver();
4208 if (resolver == null) {
4209 // may happen if the device does not support IMS.
4210 return null;
4211 }
4212 return resolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004213 } finally {
4214 Binder.restoreCallingIdentity(identity);
4215 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004216 }
4217
4218 /**
4219 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4220 * feature during emergency calling or {@link null} if the service is not available. If the
4221 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4222 * listener for feature updates.
4223 */
4224 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4225 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004226
4227 final long identity = Binder.clearCallingIdentity();
4228 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004229 ImsResolver resolver = PhoneFactory.getImsResolver();
4230 if (resolver == null) {
4231 // may happen if the device does not support IMS.
4232 return null;
4233 }
4234 return resolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004235 } finally {
4236 Binder.restoreCallingIdentity(identity);
4237 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004238 }
4239
Brad Ebinger5f64b052017-12-14 14:26:15 -08004240 /**
4241 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebingereb160e22019-01-23 15:06:19 -08004242 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004243 */
4244 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4245 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004246
4247 final long identity = Binder.clearCallingIdentity();
4248 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004249 ImsResolver resolver = PhoneFactory.getImsResolver();
4250 if (resolver == null) {
4251 // may happen if the device does not support IMS.
4252 return null;
4253 }
4254 return resolver.getImsRegistration(slotId, feature);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004255 } finally {
4256 Binder.restoreCallingIdentity(identity);
4257 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004258 }
4259
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004260 /**
4261 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebingereb160e22019-01-23 15:06:19 -08004262 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004263 */
4264 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4265 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004266
4267 final long identity = Binder.clearCallingIdentity();
4268 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004269 ImsResolver resolver = PhoneFactory.getImsResolver();
4270 if (resolver == null) {
4271 // may happen if the device does not support IMS.
4272 return null;
4273 }
4274 return resolver.getImsConfig(slotId, feature);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004275 } finally {
4276 Binder.restoreCallingIdentity(identity);
4277 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004278 }
4279
Brad Ebinger884c07b2018-02-15 16:17:40 -08004280 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004281 * Sets the ImsService Package Name that Telephony will bind to.
4282 *
4283 * @param slotId the slot ID that the ImsService should bind for.
4284 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4285 * ImsService is the device default ImsService.
4286 * @param packageName The package name of the application that contains the ImsService to bind
4287 * to.
4288 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4289 * @hide
4290 */
4291 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004292 int[] subIds = SubscriptionManager.getSubId(slotId);
4293 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4294 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4295 "setImsService");
4296
Malcolm Chend965c8b2018-02-28 15:00:40 -08004297 final long identity = Binder.clearCallingIdentity();
4298 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004299 ImsResolver resolver = PhoneFactory.getImsResolver();
4300 if (resolver == null) {
4301 // may happen if the device does not support IMS.
4302 return false;
4303 }
4304 return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService,
4305 packageName);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004306 } finally {
4307 Binder.restoreCallingIdentity(identity);
4308 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004309 }
4310
4311 /**
4312 * Return the ImsService configuration.
4313 *
4314 * @param slotId The slot that the ImsService is associated with.
4315 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4316 * the device default.
4317 * @return the package name of the ImsService configuration.
4318 */
4319 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004320 int[] subIds = SubscriptionManager.getSubId(slotId);
4321 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4322 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4323 "getImsService");
4324
Malcolm Chend965c8b2018-02-28 15:00:40 -08004325 final long identity = Binder.clearCallingIdentity();
4326 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004327 ImsResolver resolver = PhoneFactory.getImsResolver();
4328 if (resolver == null) {
4329 // may happen if the device does not support IMS.
4330 return "";
4331 }
4332 return resolver.getImsServiceConfiguration(slotId, isCarrierImsService);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004333 } finally {
4334 Binder.restoreCallingIdentity(identity);
4335 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004336 }
4337
Wink Saville36469e72014-06-11 15:17:00 -07004338 public void setImsRegistrationState(boolean registered) {
4339 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004340
4341 final long identity = Binder.clearCallingIdentity();
4342 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004343 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004344 } finally {
4345 Binder.restoreCallingIdentity(identity);
4346 }
Wink Saville36469e72014-06-11 15:17:00 -07004347 }
4348
4349 /**
Stuart Scott54788802015-03-30 13:18:01 -07004350 * Set the network selection mode to automatic.
4351 *
4352 */
4353 @Override
4354 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004355 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4356 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004357
Pengquan Meng466e2482018-09-21 15:54:48 -07004358 if (!isActiveSubscription(subId)) {
4359 return;
4360 }
4361
Malcolm Chend965c8b2018-02-28 15:00:40 -08004362 final long identity = Binder.clearCallingIdentity();
4363 try {
4364 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4365 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4366 } finally {
4367 Binder.restoreCallingIdentity(identity);
4368 }
Stuart Scott54788802015-03-30 13:18:01 -07004369 }
4370
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004371 /**
4372 * Ask the radio to connect to the input network and change selection mode to manual.
4373 *
4374 * @param subId the id of the subscription.
4375 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4376 * the operator to attach to.
4377 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4378 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4379 * normal network selection next time.
4380 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004381 */
4382 @Override
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004383 public boolean setNetworkSelectionModeManual(
4384 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004385 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4386 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Meng466e2482018-09-21 15:54:48 -07004387
4388 if (!isActiveSubscription(subId)) {
4389 return false;
4390 }
4391
Malcolm Chend965c8b2018-02-28 15:00:40 -08004392 final long identity = Binder.clearCallingIdentity();
4393 try {
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004394 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chend965c8b2018-02-28 15:00:40 -08004395 persistSelection);
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004396 if (DBG) {
4397 log("setNetworkSelectionModeManual: subId: " + subId
4398 + " operator: " + operatorInfo);
4399 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004400 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4401 } finally {
4402 Binder.restoreCallingIdentity(identity);
4403 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004404 }
4405
4406 /**
4407 * Scans for available networks.
4408 */
4409 @Override
Hall Liuf19c44f2018-11-27 14:38:17 -08004410 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004411 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4412 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004413 LocationAccessPolicy.LocationPermissionResult locationResult =
4414 LocationAccessPolicy.checkLocationPermission(mApp,
4415 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4416 .setCallingPackage(callingPackage)
4417 .setCallingPid(Binder.getCallingPid())
4418 .setCallingUid(Binder.getCallingUid())
4419 .setMethod("getCellNetworkScanResults")
4420 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4421 .build());
4422 switch (locationResult) {
4423 case DENIED_HARD:
4424 throw new SecurityException("Not allowed to access scan results -- location");
4425 case DENIED_SOFT:
4426 return null;
4427 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004428
Pengquan Meng0c05b502018-09-06 09:59:22 -07004429 long identity = Binder.clearCallingIdentity();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004430 try {
4431 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Meng0c05b502018-09-06 09:59:22 -07004432 return (CellNetworkScanResult) sendRequest(
Malcolm Chend965c8b2018-02-28 15:00:40 -08004433 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004434 } finally {
4435 Binder.restoreCallingIdentity(identity);
4436 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004437 }
4438
4439 /**
yinxub1bed742017-04-17 11:45:04 -07004440 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004441 *
yinxub1bed742017-04-17 11:45:04 -07004442 * @param subId id of the subscription
4443 * @param request contains the radio access networks with bands/channels to scan
4444 * @param messenger callback messenger for scan results or errors
4445 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004446 * @return the id of the requested scan which can be used to stop the scan.
4447 */
4448 @Override
4449 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Hall Liuf19c44f2018-11-27 14:38:17 -08004450 IBinder binder, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004451 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4452 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004453 LocationAccessPolicy.LocationPermissionResult locationResult =
4454 LocationAccessPolicy.checkLocationPermission(mApp,
4455 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4456 .setCallingPackage(callingPackage)
4457 .setCallingPid(Binder.getCallingPid())
4458 .setCallingUid(Binder.getCallingUid())
4459 .setMethod("requestNetworkScan")
4460 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4461 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004462 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
4463 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request);
4464 if (e != null) {
4465 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4466 throw e;
4467 } else {
Hall Liu46dd96a2019-04-03 12:50:44 -07004468 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004469 return TelephonyScanManager.INVALID_SCAN_ID;
4470 }
4471 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004472 }
Hall Liubac7d482019-04-25 14:02:26 -07004473 int callingUid = Binder.getCallingUid();
4474 int callingPid = Binder.getCallingPid();
yinxu612a8192019-04-18 10:38:27 -07004475 final long identity = Binder.clearCallingIdentity();
4476 try {
4477 return mNetworkScanRequestTracker.startNetworkScan(
4478 request, messenger, binder, getPhone(subId),
Hall Liubac7d482019-04-25 14:02:26 -07004479 callingUid, callingPid, callingPackage);
yinxu612a8192019-04-18 10:38:27 -07004480 } finally {
4481 Binder.restoreCallingIdentity(identity);
4482 }
yinxu504e1392017-04-12 16:03:22 -07004483 }
4484
Hall Liub2ac8ef2019-02-28 15:56:23 -08004485 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
4486 NetworkScanRequest request) {
4487 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4488 != PERMISSION_GRANTED) {
4489 return new SecurityException("permission.NETWORK_SCAN is needed for network scans"
4490 + " without location access.");
4491 }
4492
4493 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4494 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004495 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4496 return new SecurityException("Specific channels must not be"
4497 + " scanned without location access.");
4498 }
4499 }
4500 }
4501
Hall Liub2ac8ef2019-02-28 15:56:23 -08004502 return null;
4503 }
4504
yinxu504e1392017-04-12 16:03:22 -07004505 /**
4506 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004507 *
4508 * @param subId id of the subscription
4509 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004510 */
4511 @Override
4512 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004513 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4514 mApp, subId, "stopNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004515
Hall Liubac7d482019-04-25 14:02:26 -07004516 int callingUid = Binder.getCallingUid();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004517 final long identity = Binder.clearCallingIdentity();
4518 try {
Hall Liubac7d482019-04-25 14:02:26 -07004519 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004520 } finally {
4521 Binder.restoreCallingIdentity(identity);
4522 }
yinxu504e1392017-04-12 16:03:22 -07004523 }
4524
4525 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004526 * Get the calculated preferred network type.
4527 * Used for debugging incorrect network type.
4528 *
4529 * @return the preferred network type, defined in RILConstants.java.
4530 */
4531 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004532 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004533 final Phone defaultPhone = getDefaultPhone();
4534 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4535 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004536 return RILConstants.PREFERRED_NETWORK_MODE;
4537 }
4538
Malcolm Chend965c8b2018-02-28 15:00:40 -08004539 final long identity = Binder.clearCallingIdentity();
4540 try {
4541 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004542 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004543 } finally {
4544 Binder.restoreCallingIdentity(identity);
4545 }
Junda Liu84d15a22014-07-02 11:21:04 -07004546 }
4547
4548 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004549 * Get the preferred network type.
4550 * Used for device configuration by some CDMA operators.
4551 *
4552 * @return the preferred network type, defined in RILConstants.java.
4553 */
4554 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004555 public int getPreferredNetworkType(int subId) {
Pengquan Meng4848cd02018-12-20 11:00:24 -08004556 TelephonyPermissions
4557 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4558 mApp, subId, "getPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004559
4560 final long identity = Binder.clearCallingIdentity();
4561 try {
4562 if (DBG) log("getPreferredNetworkType");
4563 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4564 int networkType = (result != null ? result[0] : -1);
4565 if (DBG) log("getPreferredNetworkType: " + networkType);
4566 return networkType;
4567 } finally {
4568 Binder.restoreCallingIdentity(identity);
4569 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004570 }
4571
4572 /**
4573 * Set the preferred network type.
4574 * Used for device configuration by some CDMA operators.
4575 *
4576 * @param networkType the preferred network type, defined in RILConstants.java.
4577 * @return true on success; false on any failure.
4578 */
4579 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004580 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004581 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4582 mApp, subId, "setPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004583
4584 final long identity = Binder.clearCallingIdentity();
4585 try {
4586 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4587 Boolean success = (Boolean) sendRequest(
4588 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4589 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4590 if (success) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004591 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08004592 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4593 }
4594 return success;
4595 } finally {
4596 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004597 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004598 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004599
4600 /**
Miaoa84611c2019-03-15 09:21:10 +08004601 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004602 *
Miaoa84611c2019-03-15 09:21:10 +08004603 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004604 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004605 * @hide
4606 */
4607 @Override
Miaoa84611c2019-03-15 09:21:10 +08004608 public boolean getTetherApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004609 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004610 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08004611 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004612 try {
Miaoa84611c2019-03-15 09:21:10 +08004613 if (phone != null) {
4614 return phone.hasMatchedTetherApnSetting();
4615 } else {
4616 return false;
4617 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004618 } finally {
4619 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004620 }
Junda Liu475951f2014-11-07 16:45:03 -08004621 }
4622
4623 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004624 * Set mobile data enabled
4625 * Used by the user through settings etc to turn on/off mobile data
4626 *
4627 * @param enable {@code true} turn turn data on, else {@code false}
4628 */
4629 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004630 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004631 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4632 mApp, subId, "setUserDataEnabled");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004633
4634 final long identity = Binder.clearCallingIdentity();
4635 try {
4636 int phoneId = mSubscriptionController.getPhoneId(subId);
4637 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4638 Phone phone = PhoneFactory.getPhone(phoneId);
4639 if (phone != null) {
4640 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yu7a030e52018-12-13 11:51:28 -08004641 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004642 } else {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004643 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004644 }
4645 } finally {
4646 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004647 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004648 }
4649
4650 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004651 * Get the user enabled state of Mobile Data.
4652 *
4653 * TODO: remove and use isUserDataEnabled.
4654 * This can't be removed now because some vendor codes
4655 * calls through ITelephony directly while they should
4656 * use TelephonyManager.
4657 *
4658 * @return true on enabled
4659 */
4660 @Override
4661 public boolean getDataEnabled(int subId) {
4662 return isUserDataEnabled(subId);
4663 }
4664
4665 /**
4666 * Get whether mobile data is enabled per user setting.
4667 *
4668 * There are other factors deciding whether mobile data is actually enabled, but they are
4669 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004670 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004671 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004672 *
4673 * @return {@code true} if data is enabled else {@code false}
4674 */
4675 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004676 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004677 try {
4678 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4679 null);
4680 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004681 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4682 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004683 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004684
4685 final long identity = Binder.clearCallingIdentity();
4686 try {
4687 int phoneId = mSubscriptionController.getPhoneId(subId);
4688 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4689 Phone phone = PhoneFactory.getPhone(phoneId);
4690 if (phone != null) {
4691 boolean retVal = phone.isUserDataEnabled();
4692 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4693 return retVal;
4694 } else {
4695 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4696 return false;
4697 }
4698 } finally {
4699 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004700 }
4701 }
4702
4703 /**
4704 * Get whether mobile data is enabled.
4705 *
4706 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4707 * whether mobile data is actually enabled.
4708 *
4709 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4710 *
4711 * @return {@code true} if data is enabled else {@code false}
4712 */
4713 @Override
4714 public boolean isDataEnabled(int subId) {
4715 try {
4716 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4717 null);
4718 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004719 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4720 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004721 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004722
4723 final long identity = Binder.clearCallingIdentity();
4724 try {
4725 int phoneId = mSubscriptionController.getPhoneId(subId);
4726 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4727 Phone phone = PhoneFactory.getPhone(phoneId);
4728 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08004729 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004730 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4731 return retVal;
4732 } else {
4733 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4734 return false;
4735 }
4736 } finally {
4737 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004738 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004739 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004740
4741 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004742 public int getCarrierPrivilegeStatus(int subId) {
4743 final Phone phone = getPhone(subId);
4744 if (phone == null) {
4745 loge("getCarrierPrivilegeStatus: Invalid subId");
4746 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4747 }
4748 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004749 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004750 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004751 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4752 }
4753 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004754 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004755 }
Junda Liu29340342014-07-10 15:23:27 -07004756
4757 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004758 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4759 final Phone phone = getPhone(subId);
4760 if (phone == null) {
4761 loge("getCarrierPrivilegeStatus: Invalid subId");
4762 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4763 }
4764 UiccProfile profile =
4765 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4766 if (profile == null) {
4767 loge("getCarrierPrivilegeStatus: No UICC");
4768 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4769 }
4770 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4771 }
4772
4773 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07004774 public int checkCarrierPrivilegesForPackage(String pkgName) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004775 final Phone defaultPhone = getDefaultPhone();
Junda Liu317d70b2016-03-08 09:33:53 -08004776 if (TextUtils.isEmpty(pkgName))
4777 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004778 UiccCard card = UiccController.getInstance().getUiccCard(defaultPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004779 if (card == null) {
4780 loge("checkCarrierPrivilegesForPackage: No UICC");
4781 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4782 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004783 return card.getCarrierPrivilegeStatus(defaultPhone.getContext().getPackageManager(),
4784 pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004785 }
4786
4787 @Override
4788 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004789 if (TextUtils.isEmpty(pkgName))
4790 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004791 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4792 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4793 UiccCard card = UiccController.getInstance().getUiccCard(i);
4794 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004795 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004796 continue;
4797 }
4798
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004799 result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004800 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4801 break;
4802 }
4803 }
4804
4805 return result;
Junda Liu29340342014-07-10 15:23:27 -07004806 }
Derek Tan89e89d42014-07-08 17:00:10 -07004807
4808 @Override
Junda Liue64de782015-04-16 17:19:16 -07004809 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4810 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4811 loge("phoneId " + phoneId + " is not valid.");
4812 return null;
4813 }
4814 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004815 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004816 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004817 return null ;
4818 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004819 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004820 }
4821
Amith Yamasani6e118872016-02-19 12:53:51 -08004822 @Override
4823 public List<String> getPackagesWithCarrierPrivileges() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004824 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08004825 List<String> privilegedPackages = new ArrayList<>();
4826 List<PackageInfo> packages = null;
4827 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4828 UiccCard card = UiccController.getInstance().getUiccCard(i);
4829 if (card == null) {
4830 // No UICC in that slot.
4831 continue;
4832 }
4833 if (card.hasCarrierPrivilegeRules()) {
4834 if (packages == null) {
4835 // Only check packages in user 0 for now
4836 packages = pm.getInstalledPackagesAsUser(
4837 PackageManager.MATCH_DISABLED_COMPONENTS
4838 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4839 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
4840 }
4841 for (int p = packages.size() - 1; p >= 0; p--) {
4842 PackageInfo pkgInfo = packages.get(p);
4843 if (pkgInfo != null && pkgInfo.packageName != null
4844 && card.getCarrierPrivilegeStatus(pkgInfo)
4845 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4846 privilegedPackages.add(pkgInfo.packageName);
4847 }
4848 }
4849 }
4850 }
4851 return privilegedPackages;
4852 }
4853
Wink Savilleb564aae2014-10-23 10:18:09 -07004854 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004855 final Phone phone = getPhone(subId);
4856 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004857 if (card == null) {
4858 loge("getIccId: No UICC");
4859 return null;
4860 }
4861 String iccId = card.getIccId();
4862 if (TextUtils.isEmpty(iccId)) {
4863 loge("getIccId: ICC ID is null or empty.");
4864 return null;
4865 }
4866 return iccId;
4867 }
4868
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004869 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004870 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4871 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004872 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4873 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004874
Malcolm Chend965c8b2018-02-28 15:00:40 -08004875 final long identity = Binder.clearCallingIdentity();
4876 try {
4877 final String iccId = getIccId(subId);
4878 final Phone phone = getPhone(subId);
4879 if (phone == null) {
4880 return false;
4881 }
4882 final String subscriberId = phone.getSubscriberId();
4883
4884 if (DBG_MERGE) {
4885 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4886 + subscriberId + " to " + number);
4887 }
4888
4889 if (TextUtils.isEmpty(iccId)) {
4890 return false;
4891 }
4892
4893 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4894
4895 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4896 if (alphaTag == null) {
4897 editor.remove(alphaTagPrefKey);
4898 } else {
4899 editor.putString(alphaTagPrefKey, alphaTag);
4900 }
4901
4902 // Record both the line number and IMSI for this ICCID, since we need to
4903 // track all merged IMSIs based on line number
4904 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4905 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4906 if (number == null) {
4907 editor.remove(numberPrefKey);
4908 editor.remove(subscriberPrefKey);
4909 } else {
4910 editor.putString(numberPrefKey, number);
4911 editor.putString(subscriberPrefKey, subscriberId);
4912 }
4913
4914 editor.commit();
4915 return true;
4916 } finally {
4917 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004918 }
Derek Tan7226c842014-07-02 17:42:23 -07004919 }
4920
4921 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004922 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004923 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004924 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004925 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004926 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004927 return null;
4928 }
Derek Tan97ebb422014-09-05 16:55:38 -07004929
Malcolm Chend965c8b2018-02-28 15:00:40 -08004930 final long identity = Binder.clearCallingIdentity();
4931 try {
4932 String iccId = getIccId(subId);
4933 if (iccId != null) {
4934 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4935 if (DBG_MERGE) {
4936 log("getLine1NumberForDisplay returning "
4937 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4938 }
4939 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004940 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004941 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4942 return null;
4943 } finally {
4944 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004945 }
Derek Tan7226c842014-07-02 17:42:23 -07004946 }
4947
4948 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004949 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004950 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004951 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004952 return null;
4953 }
Derek Tan97ebb422014-09-05 16:55:38 -07004954
Malcolm Chend965c8b2018-02-28 15:00:40 -08004955 final long identity = Binder.clearCallingIdentity();
4956 try {
4957 String iccId = getIccId(subId);
4958 if (iccId != null) {
4959 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4960 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4961 }
4962 return null;
4963 } finally {
4964 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004965 }
Derek Tan7226c842014-07-02 17:42:23 -07004966 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004967
4968 @Override
Jordan Liu9775d4b2019-05-06 14:45:15 -07004969 public String[] getMergedSubscriberIds(int subId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004970 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4971 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004972 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004973 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4974 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004975 return null;
4976 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004977
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004978 final long identity = Binder.clearCallingIdentity();
4979 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004980 final Context context = mApp;
Malcolm Chend965c8b2018-02-28 15:00:40 -08004981 final TelephonyManager tele = TelephonyManager.from(context);
4982 final SubscriptionManager sub = SubscriptionManager.from(context);
4983
4984 // Figure out what subscribers are currently active
4985 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
4986 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4987 // the process, where TelephonyManager was instantiated.
4988 // Otherwise AppOps check will fail.
4989
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004990 final int[] subIds = sub.getActiveSubscriptionIdList();
Jordan Liu9775d4b2019-05-06 14:45:15 -07004991 for (int id : subIds) {
4992 // Only consider subs which match the current subId
4993 // This logic can be simplified. See b/131189269 for progress.
4994 if (subId != id) {
4995 continue;
4996 }
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004997 activeSubscriberIds.add(tele.getSubscriberId(subId));
4998 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004999
5000 // First pass, find a number override for an active subscriber
5001 String mergeNumber = null;
5002 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5003 for (String key : prefs.keySet()) {
5004 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5005 final String subscriberId = (String) prefs.get(key);
5006 if (activeSubscriberIds.contains(subscriberId)) {
5007 final String iccId = key.substring(
5008 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5009 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5010 mergeNumber = (String) prefs.get(numberKey);
5011 if (DBG_MERGE) {
5012 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5013 + " for active subscriber " + subscriberId);
5014 }
5015 if (!TextUtils.isEmpty(mergeNumber)) {
5016 break;
5017 }
5018 }
5019 }
5020 }
5021
5022 // Shortcut when no active merged subscribers
5023 if (TextUtils.isEmpty(mergeNumber)) {
5024 return null;
5025 }
5026
5027 // Second pass, find all subscribers under that line override
5028 final ArraySet<String> result = new ArraySet<>();
5029 for (String key : prefs.keySet()) {
5030 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5031 final String number = (String) prefs.get(key);
5032 if (mergeNumber.equals(number)) {
5033 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5034 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5035 final String subscriberId = (String) prefs.get(subscriberKey);
5036 if (!TextUtils.isEmpty(subscriberId)) {
5037 result.add(subscriberId);
5038 }
5039 }
5040 }
5041 }
5042
5043 final String[] resultArray = result.toArray(new String[result.size()]);
5044 Arrays.sort(resultArray);
5045 if (DBG_MERGE) {
5046 Slog.d(LOG_TAG,
5047 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5048 }
5049 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005050 } finally {
5051 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005052 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005053 }
5054
5055 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005056 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005057 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5058 subId, "setOperatorBrandOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005059
5060 final long identity = Binder.clearCallingIdentity();
5061 try {
5062 final Phone phone = getPhone(subId);
5063 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5064 } finally {
5065 Binder.restoreCallingIdentity(identity);
5066 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005067 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005068
5069 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005070 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005071 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5072 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005073 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005074
5075 final long identity = Binder.clearCallingIdentity();
5076 try {
5077 final Phone phone = getPhone(subId);
5078 if (phone == null) {
5079 return false;
5080 }
5081 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5082 cdmaNonRoamingList);
5083 } finally {
5084 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005085 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005086 }
5087
5088 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005089 @Deprecated
5090 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5091 enforceModifyPermission();
5092
5093 int returnValue = 0;
5094 try {
vagdevie435a3e2018-08-15 16:01:53 -07005095 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005096 if(result.exception == null) {
5097 if (result.result != null) {
5098 byte[] responseData = (byte[])(result.result);
5099 if(responseData.length > oemResp.length) {
5100 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5101 responseData.length + "bytes. Buffer Size is " +
5102 oemResp.length + "bytes.");
5103 }
5104 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5105 returnValue = responseData.length;
5106 }
5107 } else {
5108 CommandException ex = (CommandException) result.exception;
5109 returnValue = ex.getCommandError().ordinal();
5110 if(returnValue > 0) returnValue *= -1;
5111 }
5112 } catch (RuntimeException e) {
5113 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5114 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5115 if(returnValue > 0) returnValue *= -1;
5116 }
5117
5118 return returnValue;
5119 }
5120
5121 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005122 public void setRadioCapability(RadioAccessFamily[] rafs) {
5123 try {
5124 ProxyController.getInstance().setRadioCapability(rafs);
5125 } catch (RuntimeException e) {
5126 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5127 }
5128 }
5129
5130 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005131 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005132 Phone phone = PhoneFactory.getPhone(phoneId);
chen xufeeed752018-10-26 14:17:57 -07005133 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005134 if (phone == null) {
chen xufeeed752018-10-26 14:17:57 -07005135 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005136 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005137 final long identity = Binder.clearCallingIdentity();
5138 try {
chen xufeeed752018-10-26 14:17:57 -07005139 TelephonyPermissions
5140 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5141 mApp, phone.getSubId(), "getRadioAccessFamily");
5142 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005143 } finally {
5144 Binder.restoreCallingIdentity(identity);
5145 }
chen xufeeed752018-10-26 14:17:57 -07005146 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005147 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005148
5149 @Override
5150 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005151 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005152 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005153
5154 final long identity = Binder.clearCallingIdentity();
5155 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005156 ImsManager.getInstance(defaultPhone.getContext(),
5157 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005158 } finally {
5159 Binder.restoreCallingIdentity(identity);
5160 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005161 }
5162
5163 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005164 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005165 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00005166 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005167 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005168 return false;
5169 }
Svet Ganovb320e182015-04-16 12:30:10 -07005170
Malcolm Chend965c8b2018-02-28 15:00:40 -08005171 final long identity = Binder.clearCallingIdentity();
5172 try {
5173 // Check the user preference and the system-level IMS setting. Even if the user has
5174 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5175 // In the long run, we may instead need to check if there exists a connection service
5176 // which can support video calling.
5177 ImsManager imsManager =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005178 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005179 return imsManager.isVtEnabledByPlatform()
5180 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5181 && imsManager.isVtEnabledByUser();
5182 } finally {
5183 Binder.restoreCallingIdentity(identity);
5184 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005185 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005186
Andrew Leea1239f22015-03-02 17:44:07 -08005187 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08005188 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
5189 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5190 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5191 return false;
5192 }
5193
5194 final long identity = Binder.clearCallingIdentity();
5195 try {
5196 CarrierConfigManager configManager =
5197 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005198 return configManager.getConfigForSubId(subId)
Malcolm Chend965c8b2018-02-28 15:00:40 -08005199 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5200 } finally {
5201 Binder.restoreCallingIdentity(identity);
5202 }
Andrew Leea1239f22015-03-02 17:44:07 -08005203 }
5204
5205 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08005206 public boolean isWorldPhone(int subId, String callingPackage) {
5207 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5208 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5209 return false;
5210 }
5211
5212 final long identity = Binder.clearCallingIdentity();
5213 try {
5214 CarrierConfigManager configManager =
5215 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005216 return configManager.getConfigForSubId(subId)
Malcolm Chend965c8b2018-02-28 15:00:40 -08005217 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5218 } finally {
5219 Binder.restoreCallingIdentity(identity);
5220 }
Andrew Leea1239f22015-03-02 17:44:07 -08005221 }
5222
Andrew Lee9431b832015-03-09 18:46:45 -07005223 @Override
5224 public boolean isTtyModeSupported() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005225 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005226 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005227 }
5228
5229 @Override
5230 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005231 final long identity = Binder.clearCallingIdentity();
5232 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005233 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005234 } finally {
5235 Binder.restoreCallingIdentity(identity);
5236 }
Andrew Lee9431b832015-03-09 18:46:45 -07005237 }
5238
Hall Liuf6668912018-10-31 17:05:23 -07005239 /**
5240 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5241 * support for the feature and device firmware support.
5242 *
5243 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5244 */
5245 @Override
5246 public boolean isRttSupported(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005247 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005248 final Phone phone = getPhone(subscriptionId);
5249 if (phone == null) {
5250 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5251 return false;
5252 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005253 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005254 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chend965c8b2018-02-28 15:00:40 -08005255 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5256 boolean isDeviceSupported =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005257 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005258 return isCarrierSupported && isDeviceSupported;
5259 } finally {
5260 Binder.restoreCallingIdentity(identity);
5261 }
Hall Liu98187582018-01-22 19:15:32 -08005262 }
5263
Hall Liuf6668912018-10-31 17:05:23 -07005264 /**
5265 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
5266 * both also support RTT.
5267 */
5268 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005269 final long identity = Binder.clearCallingIdentity();
5270 try {
Hall Liuf6668912018-10-31 17:05:23 -07005271 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005272 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005273 } finally {
5274 Binder.restoreCallingIdentity(identity);
5275 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005276 }
5277
Sanket Padawe7310cc72015-01-14 09:53:20 -08005278 /**
5279 * Returns the unique device ID of phone, for example, the IMEI for
5280 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5281 *
5282 * <p>Requires Permission:
5283 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5284 */
5285 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005286 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005287 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005288 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005289 return null;
5290 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005291 int subId = phone.getSubId();
5292 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5293 mApp, subId, callingPackage, "getDeviceId")) {
5294 return null;
5295 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005296
5297 final long identity = Binder.clearCallingIdentity();
5298 try {
5299 return phone.getDeviceId();
5300 } finally {
5301 Binder.restoreCallingIdentity(identity);
5302 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005303 }
5304
Ping Sunc67b7c22016-03-02 19:16:45 +08005305 /**
5306 * {@hide}
5307 * Returns the IMS Registration Status on a particular subid
5308 *
5309 * @param subId
5310 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005311 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005312 Phone phone = getPhone(subId);
5313 if (phone != null) {
5314 return phone.isImsRegistered();
5315 } else {
5316 return false;
5317 }
5318 }
5319
Santos Cordon7a1885b2015-02-03 11:15:19 -08005320 @Override
5321 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005322 final long identity = Binder.clearCallingIdentity();
5323 try {
5324 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5325 } finally {
5326 Binder.restoreCallingIdentity(identity);
5327 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005328 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005329
Tyler Gunn327a9722019-04-03 15:28:53 -07005330 @Override
5331 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5332 final long identity = Binder.clearCallingIdentity();
5333 try {
5334 Phone phone = getPhone(subscriptionId);
5335 if (phone == null) {
5336 return null;
5337 }
5338 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5339 } finally {
5340 Binder.restoreCallingIdentity(identity);
5341 }
5342 }
5343
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005344 /**
5345 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005346 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005347 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005348 final long identity = Binder.clearCallingIdentity();
5349 try {
5350 Phone phone = getPhone(subId);
5351 if (phone != null) {
5352 return phone.isWifiCallingEnabled();
5353 } else {
5354 return false;
5355 }
5356 } finally {
5357 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005358 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005359 }
5360
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005361 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005362 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005363 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005364 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005365 final long identity = Binder.clearCallingIdentity();
5366 try {
5367 Phone phone = getPhone(subId);
5368 if (phone != null) {
5369 return phone.isVideoEnabled();
5370 } else {
5371 return false;
5372 }
5373 } finally {
5374 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005375 }
5376 }
5377
5378 /**
5379 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5380 * defined in {@link ImsRegistrationImplBase}.
5381 */
5382 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005383 final long identity = Binder.clearCallingIdentity();
5384 try {
5385 Phone phone = getPhone(subId);
5386 if (phone != null) {
5387 return phone.getImsRegistrationTech();
5388 } else {
5389 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5390 }
5391 } finally {
5392 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005393 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005394 }
5395
Stuart Scott8eef64f2015-04-08 15:13:54 -07005396 @Override
5397 public void factoryReset(int subId) {
5398 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005399 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5400 return;
5401 }
5402
Svet Ganovcc087f82015-05-12 20:35:54 -07005403 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005404
Svet Ganovcc087f82015-05-12 20:35:54 -07005405 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005406 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5407 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005408 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005409 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005410 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005411 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5412 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005413 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005414 // There has been issues when Sms raw table somehow stores orphan
5415 // fragments. They lead to garbled message when new fragments come
5416 // in and combined with those stale ones. In case this happens again,
5417 // user can reset all network settings which will clean up this table.
5418 cleanUpSmsRawTable(getDefaultPhone().getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07005419 } finally {
5420 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005421 }
5422 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005423
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005424 private void cleanUpSmsRawTable(Context context) {
5425 ContentResolver resolver = context.getContentResolver();
5426 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5427 resolver.delete(uri, null, null);
5428 }
5429
Narayan Kamath1c496c22015-04-16 14:40:19 +01005430 @Override
chen xu2e6dfec2019-01-21 23:31:38 -08005431 public String getSimLocaleForSubscriber(int subId) {
5432 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5433 final Phone phone = getPhone(subId);
5434 if (phone == null) {
5435 log("getSimLocaleForSubscriber, invalid subId");
Pengquan Meng9c291482019-01-28 16:26:29 -08005436 return null;
chen xu2e6dfec2019-01-21 23:31:38 -08005437 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005438 final long identity = Binder.clearCallingIdentity();
5439 try {
chen xu2e6dfec2019-01-21 23:31:38 -08005440 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5441 phone.getContext().getOpPackageName());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005442 // Try and fetch the locale from the carrier properties or from the SIM language
5443 // preferences (EF-PL and EF-LI)...
5444 final int mcc = info.getMcc();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005445 String simLanguage = null;
chen xu2e6dfec2019-01-21 23:31:38 -08005446 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5447 if (localeFromDefaultSim != null) {
5448 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5449 if (DBG) log("Using locale from subId: " + subId + " locale: "
5450 + localeFromDefaultSim);
5451 return localeFromDefaultSim.toLanguageTag();
5452 } else {
5453 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005454 }
5455 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005456
Malcolm Chend965c8b2018-02-28 15:00:40 -08005457 // The SIM language preferences only store a language (e.g. fr = French), not an
5458 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5459 // the SIM and carrier preferences does not include a country we add the country
5460 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005461 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005462 if (mccLocale != null) {
chen xu2e6dfec2019-01-21 23:31:38 -08005463 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005464 return mccLocale.toLanguageTag();
5465 }
5466
5467 if (DBG) log("No locale found - returning null");
5468 return null;
5469 } finally {
5470 Binder.restoreCallingIdentity(identity);
5471 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005472 }
5473
5474 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005475 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005476 }
5477
Malcolm Chend965c8b2018-02-28 15:00:40 -08005478 /**
5479 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5480 */
5481 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005482 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005483 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005484
Chenjie Yu1ba97252018-01-11 18:16:20 -08005485 private final ModemActivityInfo mLastModemActivityInfo =
5486 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
5487
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005488 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005489 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5490 * representing the state of the modem.
5491 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005492 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5493 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005494 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005495 */
5496 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005497 public void requestModemActivityInfo(ResultReceiver result) {
5498 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005499 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005500
5501 final long identity = Binder.clearCallingIdentity();
5502 try {
5503 ModemActivityInfo ret = null;
5504 synchronized (mLastModemActivityInfo) {
vagdevie435a3e2018-08-15 16:01:53 -07005505 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5506 CMD_GET_MODEM_ACTIVITY_INFO,
5507 null, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005508 if (isModemActivityInfoValid(info)) {
5509 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
5510 for (int i = 0; i < mergedTxTimeMs.length; i++) {
5511 mergedTxTimeMs[i] =
5512 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
5513 }
5514 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
5515 mLastModemActivityInfo.setSleepTimeMillis(
5516 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
5517 mLastModemActivityInfo.setIdleTimeMillis(
5518 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
5519 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
5520 mLastModemActivityInfo.setRxTimeMillis(
5521 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
5522 mLastModemActivityInfo.setEnergyUsed(
5523 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005524 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005525 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
5526 mLastModemActivityInfo.getSleepTimeMillis(),
5527 mLastModemActivityInfo.getIdleTimeMillis(),
5528 mLastModemActivityInfo.getTxTimeMillis(),
5529 mLastModemActivityInfo.getRxTimeMillis(),
5530 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005531 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005532 Bundle bundle = new Bundle();
5533 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
5534 result.send(0, bundle);
5535 } finally {
5536 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005537 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005538 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005539
Siddharth Rayf5d29552018-06-17 15:02:38 -07005540 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
5541 // less than total activity duration.
5542 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
5543 if (info == null) {
5544 return false;
5545 }
5546 int activityDurationMs =
5547 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
5548 int totalTxTimeMs = 0;
5549 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
5550 totalTxTimeMs += info.getTxTimeMillis()[i];
5551 }
5552 return (info.isValid()
5553 && (info.getSleepTimeMillis() <= activityDurationMs)
5554 && (info.getIdleTimeMillis() <= activityDurationMs)
5555 && (info.getRxTimeMillis() <= activityDurationMs)
5556 && (totalTxTimeMs <= activityDurationMs));
5557 }
5558
Jack Yu85bd38a2015-11-09 11:34:32 -08005559 /**
5560 * {@hide}
5561 * Returns the service state information on specified subscription.
5562 */
5563 @Override
5564 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005565 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005566 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08005567 return null;
5568 }
5569
Hall Liuf19c44f2018-11-27 14:38:17 -08005570 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
5571 LocationAccessPolicy.checkLocationPermission(mApp,
5572 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5573 .setCallingPackage(callingPackage)
5574 .setCallingPid(Binder.getCallingPid())
5575 .setCallingUid(Binder.getCallingUid())
5576 .setMethod("getServiceStateForSubscriber")
Hall Liu8b0cba22019-04-17 13:37:11 -07005577 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005578 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5579 .build());
5580
5581 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
5582 LocationAccessPolicy.checkLocationPermission(mApp,
5583 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5584 .setCallingPackage(callingPackage)
5585 .setCallingPid(Binder.getCallingPid())
5586 .setCallingUid(Binder.getCallingUid())
5587 .setMethod("getServiceStateForSubscriber")
Hall Liu8b0cba22019-04-17 13:37:11 -07005588 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005589 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5590 .build());
5591 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
5592 boolean hasFinePermission =
5593 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5594 boolean hasCoarsePermission =
5595 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5596
Malcolm Chend965c8b2018-02-28 15:00:40 -08005597 final long identity = Binder.clearCallingIdentity();
5598 try {
5599 final Phone phone = getPhone(subId);
5600 if (phone == null) {
5601 return null;
5602 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005603
Hall Liuf19c44f2018-11-27 14:38:17 -08005604 ServiceState ss = phone.getServiceState();
5605
5606 // Scrub out the location info in ServiceState depending on what level of access
5607 // the caller has.
5608 if (hasFinePermission) return ss;
5609 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
5610 return ss.sanitizeLocationInfo(true);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005611 } finally {
5612 Binder.restoreCallingIdentity(identity);
5613 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005614 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005615
5616 /**
5617 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
5618 *
5619 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5620 * voicemail ringtone.
5621 * @return The URI for the ringtone to play when receiving a voicemail from a specific
5622 * PhoneAccount.
5623 */
5624 @Override
5625 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005626 final long identity = Binder.clearCallingIdentity();
5627 try {
5628 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5629 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005630 phone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005631 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005632
Malcolm Chend965c8b2018-02-28 15:00:40 -08005633 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
5634 } finally {
5635 Binder.restoreCallingIdentity(identity);
5636 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005637 }
5638
5639 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005640 * Sets the per-account voicemail ringtone.
5641 *
5642 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5643 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5644 *
5645 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5646 * voicemail ringtone.
5647 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5648 * PhoneAccount.
5649 */
5650 @Override
5651 public void setVoicemailRingtoneUri(String callingPackage,
5652 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005653 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005654 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5655 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005656 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005657 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5658 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5659 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005660 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005661
5662 final long identity = Binder.clearCallingIdentity();
5663 try {
5664 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5665 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005666 phone = defaultPhone;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005667 }
5668 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5669 } finally {
5670 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005671 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005672 }
5673
5674 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005675 * Returns whether vibration is set for voicemail notification in Phone settings.
5676 *
5677 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5678 * voicemail vibration setting.
5679 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5680 */
5681 @Override
5682 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005683 final long identity = Binder.clearCallingIdentity();
5684 try {
5685 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5686 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005687 phone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005688 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005689
Malcolm Chend965c8b2018-02-28 15:00:40 -08005690 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5691 } finally {
5692 Binder.restoreCallingIdentity(identity);
5693 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005694 }
5695
Youhan Wange64578a2016-05-02 15:32:42 -07005696 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005697 * Sets the per-account voicemail vibration.
5698 *
5699 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5700 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5701 *
5702 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5703 * voicemail vibration setting.
5704 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5705 * specific PhoneAccount.
5706 */
5707 @Override
5708 public void setVoicemailVibrationEnabled(String callingPackage,
5709 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005710 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005711 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5712 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005713 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005714 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5715 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5716 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005717 }
5718
Malcolm Chend965c8b2018-02-28 15:00:40 -08005719 final long identity = Binder.clearCallingIdentity();
5720 try {
5721 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5722 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005723 phone = defaultPhone;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005724 }
5725 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5726 } finally {
5727 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005728 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005729 }
5730
5731 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005732 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5733 *
5734 * @throws SecurityException if the caller does not have the required permission
5735 */
Brad Ebinger4c460712018-10-01 10:40:55 -07005736 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005737 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger4c460712018-10-01 10:40:55 -07005738 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005739 }
5740
5741 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005742 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5743 * permission.
5744 *
5745 * @throws SecurityException if the caller does not have the required permission
5746 */
5747 private void enforceSendSmsPermission() {
5748 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5749 }
5750
5751 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005752 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005753 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005754 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005755 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005756 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005757 final long identity = Binder.clearCallingIdentity();
5758 try {
5759 ComponentName componentName =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005760 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005761 if (componentName == null) {
5762 throw new SecurityException(
5763 "Caller not current active visual voicemail package[null]");
5764 }
5765 String vvmPackage = componentName.getPackageName();
5766 if (!callingPackage.equals(vvmPackage)) {
5767 throw new SecurityException("Caller not current active visual voicemail package["
5768 + vvmPackage + "]");
5769 }
5770 } finally {
5771 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005772 }
5773 }
5774
5775 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005776 * Return the application ID for the app type.
5777 *
5778 * @param subId the subscription ID that this request applies to.
5779 * @param appType the uicc app type.
5780 * @return Application ID for specificied app type, or null if no uicc.
5781 */
5782 @Override
5783 public String getAidForAppType(int subId, int appType) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005784 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005785 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005786
5787 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005788 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005789 if (phone == null) {
5790 return null;
5791 }
5792 String aid = null;
5793 try {
5794 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5795 .getApplicationByType(appType).getAid();
5796 } catch (Exception e) {
5797 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5798 }
5799 return aid;
5800 } finally {
5801 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005802 }
Youhan Wange64578a2016-05-02 15:32:42 -07005803 }
5804
Youhan Wang4001d252016-05-11 10:29:41 -07005805 /**
5806 * Return the Electronic Serial Number.
5807 *
5808 * @param subId the subscription ID that this request applies to.
5809 * @return ESN or null if error.
5810 */
5811 @Override
5812 public String getEsn(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005813 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005814 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005815
5816 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005817 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005818 if (phone == null) {
5819 return null;
5820 }
5821 String esn = null;
5822 try {
5823 esn = phone.getEsn();
5824 } catch (Exception e) {
5825 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5826 }
5827 return esn;
5828 } finally {
5829 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005830 }
Youhan Wang4001d252016-05-11 10:29:41 -07005831 }
5832
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005833 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005834 * Return the Preferred Roaming List Version.
5835 *
5836 * @param subId the subscription ID that this request applies to.
5837 * @return PRLVersion or null if error.
5838 */
5839 @Override
5840 public String getCdmaPrlVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005841 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005842 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005843
5844 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005845 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005846 if (phone == null) {
5847 return null;
5848 }
5849 String cdmaPrlVersion = null;
5850 try {
5851 cdmaPrlVersion = phone.getCdmaPrlVersion();
5852 } catch (Exception e) {
5853 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5854 }
5855 return cdmaPrlVersion;
5856 } finally {
5857 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005858 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005859 }
5860
5861 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005862 * Get snapshot of Telephony histograms
5863 * @return List of Telephony histograms
5864 * @hide
5865 */
5866 @Override
5867 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005868 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5869 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005870
5871 final long identity = Binder.clearCallingIdentity();
5872 try {
5873 return RIL.getTelephonyRILTimingHistograms();
5874 } finally {
5875 Binder.restoreCallingIdentity(identity);
5876 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005877 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005878
5879 /**
5880 * {@hide}
Michele Berionne0963c862018-11-27 18:57:59 -08005881 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
5882 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005883 * Require system privileges. In the future we may add this to carrier APIs.
5884 *
Michele Berionne0963c862018-11-27 18:57:59 -08005885 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005886 */
5887 @Override
Michele Berionne0963c862018-11-27 18:57:59 -08005888 @TelephonyManager.SetCarrierRestrictionResult
5889 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005890 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005891 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005892
Michele Berionne0963c862018-11-27 18:57:59 -08005893 if (carrierRestrictionRules == null) {
5894 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08005895 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005896
Malcolm Chend965c8b2018-02-28 15:00:40 -08005897 final long identity = Binder.clearCallingIdentity();
5898 try {
Michele Berionne0963c862018-11-27 18:57:59 -08005899 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdevie435a3e2018-08-15 16:01:53 -07005900 workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005901 } finally {
5902 Binder.restoreCallingIdentity(identity);
5903 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005904 }
5905
5906 /**
5907 * {@hide}
Michele Berionne0963c862018-11-27 18:57:59 -08005908 * Get the allowed carrier list and the excluded carrier list, including the priority between
5909 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005910 * Require system privileges. In the future we may add this to carrier APIs.
5911 *
Michele Berionne0963c862018-11-27 18:57:59 -08005912 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07005913 */
5914 @Override
Michele Berionne0963c862018-11-27 18:57:59 -08005915 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger4c460712018-10-01 10:40:55 -07005916 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdevie435a3e2018-08-15 16:01:53 -07005917 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005918
5919 final long identity = Binder.clearCallingIdentity();
5920 try {
Michele Berionne0963c862018-11-27 18:57:59 -08005921 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
5922 if (response instanceof CarrierRestrictionRules) {
5923 return (CarrierRestrictionRules) response;
5924 }
5925 // Response is an Exception of some kind,
5926 // which is signalled to the user as a NULL retval
5927 return null;
5928 } catch (Exception e) {
5929 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
5930 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005931 } finally {
5932 Binder.restoreCallingIdentity(identity);
5933 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005934 }
5935
fionaxu59545b42016-05-25 15:53:37 -07005936 /**
5937 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5938 * @param subId the subscription ID that this action applies to.
5939 * @param enabled control enable or disable metered apns.
5940 * {@hide}
5941 */
5942 @Override
5943 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5944 enforceModifyPermission();
5945 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005946
5947 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005948 if (phone == null) {
5949 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5950 return;
5951 }
5952 try {
5953 phone.carrierActionSetMeteredApnsEnabled(enabled);
5954 } catch (Exception e) {
5955 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005956 } finally {
5957 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005958 }
5959 }
5960
5961 /**
5962 * Action set from carrier signalling broadcast receivers to enable/disable radio
5963 * @param subId the subscription ID that this action applies to.
5964 * @param enabled control enable or disable radio.
5965 * {@hide}
5966 */
5967 @Override
5968 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5969 enforceModifyPermission();
5970 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005971
5972 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005973 if (phone == null) {
5974 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5975 return;
5976 }
5977 try {
5978 phone.carrierActionSetRadioEnabled(enabled);
5979 } catch (Exception e) {
5980 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005981 } finally {
5982 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005983 }
5984 }
5985
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005986 /**
fionaxu8da9cb12017-05-23 15:02:46 -07005987 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
5988 * network status based on which carrier apps could apply actions accordingly,
5989 * enable/disable default url handler for example.
5990 *
5991 * @param subId the subscription ID that this action applies to.
5992 * @param report control start/stop reporting the default network status.
5993 * {@hide}
5994 */
5995 @Override
5996 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
5997 enforceModifyPermission();
5998 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005999
6000 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006001 if (phone == null) {
6002 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6003 return;
6004 }
6005 try {
6006 phone.carrierActionReportDefaultNetworkStatus(report);
6007 } catch (Exception e) {
6008 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08006009 } finally {
6010 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006011 }
6012 }
6013
6014 /**
fionaxud9622282017-07-17 17:51:30 -07006015 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6016 * @param subId the subscription ID that this action applies to.
6017 * {@hide}
6018 */
6019 @Override
6020 public void carrierActionResetAll(int subId) {
6021 enforceModifyPermission();
6022 final Phone phone = getPhone(subId);
6023 if (phone == null) {
6024 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6025 return;
6026 }
6027 try {
6028 phone.carrierActionResetAll();
6029 } catch (Exception e) {
6030 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6031 }
6032 }
6033
6034 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006035 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6036 * bug report is being generated.
6037 */
6038 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006039 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006040 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6041 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006042 writer.println("Permission Denial: can't dump Phone from pid="
6043 + Binder.getCallingPid()
6044 + ", uid=" + Binder.getCallingUid()
6045 + "without permission "
6046 + android.Manifest.permission.DUMP);
6047 return;
6048 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006049 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006050 }
Jack Yueb89b242016-06-22 13:27:47 -07006051
Brad Ebingerdac2f002018-04-03 15:17:52 -07006052 @Override
6053 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6054 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6055 throws RemoteException {
6056 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
6057 }
6058
Jack Yueb89b242016-06-22 13:27:47 -07006059 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006060 * Get aggregated video call data usage since boot.
6061 *
6062 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6063 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006064 * {@hide}
6065 */
6066 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006067 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006068 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6069 null);
6070
Malcolm Chend965c8b2018-02-28 15:00:40 -08006071 final long identity = Binder.clearCallingIdentity();
6072 try {
6073 // NetworkStatsService keeps tracking the active network interface and identity. It
6074 // records the delta with the corresponding network identity.
6075 // We just return the total video call data usage snapshot since boot.
6076 Phone phone = getPhone(subId);
6077 if (phone != null) {
6078 return phone.getVtDataUsage(perUidStats);
6079 }
6080 return null;
6081 } finally {
6082 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006083 }
Jack Yueb89b242016-06-22 13:27:47 -07006084 }
Jack Yu75ab2952016-07-08 14:29:33 -07006085
6086 /**
6087 * Policy control of data connection. Usually used when data limit is passed.
6088 * @param enabled True if enabling the data, otherwise disabling.
6089 * @param subId Subscription index
6090 * {@hide}
6091 */
6092 @Override
6093 public void setPolicyDataEnabled(boolean enabled, int subId) {
6094 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08006095
6096 final long identity = Binder.clearCallingIdentity();
6097 try {
6098 Phone phone = getPhone(subId);
6099 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08006100 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chend965c8b2018-02-28 15:00:40 -08006101 }
6102 } finally {
6103 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006104 }
6105 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006106
6107 /**
6108 * Get Client request stats
6109 * @return List of Client Request Stats
6110 * @hide
6111 */
6112 @Override
6113 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006114 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006115 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006116 return null;
6117 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006118 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006119
Malcolm Chend965c8b2018-02-28 15:00:40 -08006120 final long identity = Binder.clearCallingIdentity();
6121 try {
6122 if (phone != null) {
6123 return phone.getClientRequestStats();
6124 }
6125
6126 return null;
6127 } finally {
6128 Binder.restoreCallingIdentity(identity);
6129 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006130 }
6131
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006132 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006133 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006134 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006135 }
Jack Yueb4124c2017-02-16 15:32:43 -08006136
6137 /**
Grace Chen70990072017-03-24 17:21:30 -07006138 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006139 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006140 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006141 * @param state State of SIM (power down, power up, pass through)
6142 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6143 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6144 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006145 *
6146 **/
6147 @Override
Grace Chen70990072017-03-24 17:21:30 -07006148 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006149 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006150 Phone phone = PhoneFactory.getPhone(slotIndex);
6151
vagdevie435a3e2018-08-15 16:01:53 -07006152 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6153
Malcolm Chend965c8b2018-02-28 15:00:40 -08006154 final long identity = Binder.clearCallingIdentity();
6155 try {
6156 if (phone != null) {
vagdevie435a3e2018-08-15 16:01:53 -07006157 phone.setSimPowerState(state, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08006158 }
6159 } finally {
6160 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006161 }
6162 }
Shuo Qiandd210312017-04-12 22:11:33 +00006163
Tyler Gunn65d45c22017-06-05 11:22:26 -07006164 private boolean isUssdApiAllowed(int subId) {
6165 CarrierConfigManager configManager =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006166 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006167 if (configManager == null) {
6168 return false;
6169 }
6170 PersistableBundle pb = configManager.getConfigForSubId(subId);
6171 if (pb == null) {
6172 return false;
6173 }
6174 return pb.getBoolean(
6175 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6176 }
6177
Shuo Qiandd210312017-04-12 22:11:33 +00006178 /**
6179 * Check if phone is in emergency callback mode
6180 * @return true if phone is in emergency callback mode
6181 * @param subId sub id
6182 */
goneil9c5f4872017-12-05 14:07:56 -08006183 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006184 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07006185 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006186 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08006187
6188 final long identity = Binder.clearCallingIdentity();
6189 try {
6190 if (phone != null) {
6191 return phone.isInEcm();
6192 } else {
6193 return false;
6194 }
6195 } finally {
6196 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006197 }
6198 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006199
6200 /**
6201 * Get the current signal strength information for the given subscription.
6202 * Because this information is not updated when the device is in a low power state
6203 * it should not be relied-upon to be current.
6204 * @param subId Subscription index
6205 * @return the most recent cached signal strength info from the modem
6206 */
6207 @Override
6208 public SignalStrength getSignalStrength(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08006209 final long identity = Binder.clearCallingIdentity();
6210 try {
6211 Phone p = getPhone(subId);
6212 if (p == null) {
6213 return null;
6214 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006215
Malcolm Chend965c8b2018-02-28 15:00:40 -08006216 return p.getSignalStrength();
6217 } finally {
6218 Binder.restoreCallingIdentity(identity);
6219 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006220 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006221
Pengquan Meng9140aec2018-08-22 14:49:57 -07006222 /**
chen xu907e5a22018-10-11 13:21:04 -07006223 * Get the current modem radio state for the given slot.
6224 * @param slotIndex slot index.
6225 * @param callingPackage the name of the package making the call.
6226 * @return the current radio power state from the modem
6227 */
6228 @Override
6229 public int getRadioPowerState(int slotIndex, String callingPackage) {
6230 Phone phone = PhoneFactory.getPhone(slotIndex);
6231 if (phone != null) {
6232 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6233 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
6234 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6235 }
6236
6237 final long identity = Binder.clearCallingIdentity();
6238 try {
6239 return phone.getRadioPowerState();
6240 } finally {
6241 Binder.restoreCallingIdentity(identity);
6242 }
6243 }
6244 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6245 }
6246
6247 /**
Pengquan Meng9140aec2018-08-22 14:49:57 -07006248 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6249 *
6250 * <p>Requires one of the following permissions:
6251 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6252 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6253 * privileges.
6254 *
6255 * @param subId subscription id
6256 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6257 * {@code false}.
6258 */
6259 @Override
6260 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006261 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6262 null /* message */);
6263
Pengquan Meng0c05b502018-09-06 09:59:22 -07006264 boolean isEnabled = false;
6265 final long identity = Binder.clearCallingIdentity();
Pengquan Meng9140aec2018-08-22 14:49:57 -07006266 try {
Pengquan Meng0c05b502018-09-06 09:59:22 -07006267 Phone phone = getPhone(subId);
6268 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng9140aec2018-08-22 14:49:57 -07006269 } catch (Exception e) {
6270 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6271 mApp, subId, "isDataRoamingEnabled");
Pengquan Meng0c05b502018-09-06 09:59:22 -07006272 } finally {
6273 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07006274 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07006275 return isEnabled;
Pengquan Meng9140aec2018-08-22 14:49:57 -07006276 }
6277
6278
6279 /**
6280 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6281 *
6282 * <p> Requires permission:
6283 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6284 * privileges.
6285 *
6286 * @param subId subscription id
6287 * @param isEnabled {@code true} means enable, {@code false} means disable.
6288 */
6289 @Override
6290 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006291 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6292 mApp, subId, "setDataRoamingEnabled");
6293
Pengquan Meng0c05b502018-09-06 09:59:22 -07006294 final long identity = Binder.clearCallingIdentity();
6295 try {
Pengquan Meng0c05b502018-09-06 09:59:22 -07006296 Phone phone = getPhone(subId);
6297 if (phone != null) {
6298 phone.setDataRoamingEnabled(isEnabled);
6299 }
6300 } finally {
6301 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07006302 }
6303 }
6304
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006305 @Override
Pengquan Meng312de0c2018-10-03 12:19:13 -07006306 public boolean isManualNetworkSelectionAllowed(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006307 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6308 mApp, subId, "isManualNetworkSelectionAllowed");
6309
Pengquan Meng312de0c2018-10-03 12:19:13 -07006310 boolean isAllowed = true;
6311 final long identity = Binder.clearCallingIdentity();
6312 try {
Pengquan Meng312de0c2018-10-03 12:19:13 -07006313 Phone phone = getPhone(subId);
6314 if (phone != null) {
6315 isAllowed = phone.isCspPlmnEnabled();
6316 }
6317 } finally {
6318 Binder.restoreCallingIdentity(identity);
6319 }
6320 return isAllowed;
6321 }
6322
6323 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006324 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu67997952019-04-22 15:10:43 -07006325 boolean hasReadPermission = false;
Jordan Liu53fdb782019-02-12 17:54:02 -08006326 try {
6327 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu67997952019-04-22 15:10:43 -07006328 hasReadPermission = true;
Jordan Liu53fdb782019-02-12 17:54:02 -08006329 } catch (SecurityException e) {
6330 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6331 // has carrier privileges on an active UICC
6332 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6333 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu67997952019-04-22 15:10:43 -07006334 throw new SecurityException("Caller does not have permission.");
Jordan Liu53fdb782019-02-12 17:54:02 -08006335 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006336 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006337
6338 final long identity = Binder.clearCallingIdentity();
6339 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006340 UiccController uiccController = UiccController.getInstance();
6341 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu67997952019-04-22 15:10:43 -07006342 if (hasReadPermission) {
6343 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006344 }
Jordan Liu67997952019-04-22 15:10:43 -07006345
6346 // Remove private info if the caller doesn't have access
6347 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6348 for (UiccCardInfo cardInfo : cardInfos) {
6349 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6350 // is available
6351 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
6352 if (card == null || card.getUiccProfile() == null) {
6353 // assume no access if the card or profile is unavailable
6354 filteredInfos.add(cardInfo.getUnprivileged());
6355 continue;
6356 }
6357 UiccProfile profile = card.getUiccProfile();
6358 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6359 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6360 filteredInfos.add(cardInfo);
6361 } else {
6362 filteredInfos.add(cardInfo.getUnprivileged());
6363 }
6364 }
6365 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08006366 } finally {
6367 Binder.restoreCallingIdentity(identity);
6368 }
6369 }
6370
6371 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006372 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger4c460712018-10-01 10:40:55 -07006373 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006374
Malcolm Chend965c8b2018-02-28 15:00:40 -08006375 final long identity = Binder.clearCallingIdentity();
6376 try {
6377 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6378 if (slots == null) {
6379 Rlog.i(LOG_TAG, "slots is null.");
6380 return null;
6381 }
6382
6383 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6384 for (int i = 0; i < slots.length; i++) {
6385 UiccSlot slot = slots[i];
6386 if (slot == null) {
6387 continue;
6388 }
6389
6390 String cardId;
6391 UiccCard card = slot.getUiccCard();
6392 if (card != null) {
6393 cardId = card.getCardId();
6394 } else {
6395 cardId = slot.getIccId();
6396 }
6397
Jordan Liu857451f2019-05-09 16:35:35 -07006398 if (cardId != null) {
6399 // if cardId is an ICCID, strip off trailing Fs before exposing to user
6400 // if cardId is an EID, it's all digits so this is fine
6401 cardId = IccUtils.stripTrailingFs(cardId);
6402 }
6403
Malcolm Chend965c8b2018-02-28 15:00:40 -08006404 int cardState = 0;
6405 switch (slot.getCardState()) {
6406 case CARDSTATE_ABSENT:
6407 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6408 break;
6409 case CARDSTATE_PRESENT:
6410 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6411 break;
6412 case CARDSTATE_ERROR:
6413 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6414 break;
6415 case CARDSTATE_RESTRICTED:
6416 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6417 break;
6418 default:
6419 break;
6420
6421 }
6422
6423 infos[i] = new UiccSlotInfo(
6424 slot.isActive(),
6425 slot.isEuicc(),
6426 cardId,
6427 cardState,
6428 slot.getPhoneId(),
Jordan Liuef65d872019-02-14 12:56:40 -08006429 slot.isExtendedApduSupported(),
6430 slot.isRemovable());
Malcolm Chend965c8b2018-02-28 15:00:40 -08006431 }
6432 return infos;
6433 } finally {
6434 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006435 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006436 }
6437
6438 @Override
6439 public boolean switchSlots(int[] physicalSlots) {
6440 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08006441
6442 final long identity = Binder.clearCallingIdentity();
6443 try {
6444 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6445 } finally {
6446 Binder.restoreCallingIdentity(identity);
6447 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006448 }
Jack Yu4c988042018-02-27 15:30:01 -08006449
6450 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006451 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006452 final long identity = Binder.clearCallingIdentity();
6453 try {
6454 return UiccController.getInstance().getCardIdForDefaultEuicc();
6455 } finally {
6456 Binder.restoreCallingIdentity(identity);
6457 }
6458 }
6459
6460 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006461 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6462 enforceModifyPermission();
6463 final Phone phone = getPhone(subId);
6464 if (phone == null) {
6465 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6466 return;
6467 }
6468
Malcolm Chend965c8b2018-02-28 15:00:40 -08006469 final long identity = Binder.clearCallingIdentity();
6470 try {
6471 phone.setRadioIndicationUpdateMode(filters, mode);
6472 } finally {
6473 Binder.restoreCallingIdentity(identity);
6474 }
Jack Yu4c988042018-02-27 15:30:01 -08006475 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006476
6477 /**
goneil47ffb6e2018-04-06 15:40:58 -07006478 * A test API to reload the UICC profile.
6479 *
6480 * <p>Requires that the calling app has permission
6481 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6482 * @hide
6483 */
6484 @Override
6485 public void refreshUiccProfile(int subId) {
6486 enforceModifyPermission();
6487
6488 final long identity = Binder.clearCallingIdentity();
6489 try {
6490 Phone phone = getPhone(subId);
6491 if (phone == null) {
6492 return;
6493 }
6494 UiccCard uiccCard = phone.getUiccCard();
6495 if (uiccCard == null) {
6496 return;
6497 }
6498 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6499 if (uiccProfile == null) {
6500 return;
6501 }
6502 uiccProfile.refresh();
6503 } finally {
6504 Binder.restoreCallingIdentity(identity);
6505 }
6506 }
6507
6508 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006509 * Returns false if the mobile data is disabled by default, otherwise return true.
6510 */
6511 private boolean getDefaultDataEnabled() {
6512 return "true".equalsIgnoreCase(
6513 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
6514 }
6515
6516 /**
6517 * Returns true if the data roaming is enabled by default, i.e the system property
6518 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
6519 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
6520 */
6521 private boolean getDefaultDataRoamingEnabled(int subId) {
6522 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006523 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006524 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
6525 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
6526 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
6527 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
6528 return isDataRoamingEnabled;
6529 }
6530
6531 /**
6532 * Returns the default network type for the given {@code subId}, if the default network type is
6533 * not set, return {@link Phone#PREFERRED_NT_MODE}.
6534 */
6535 private int getDefaultNetworkType(int subId) {
6536 return Integer.parseInt(
6537 TelephonyManager.getTelephonyProperty(
6538 mSubscriptionController.getPhoneId(subId),
6539 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
6540 String.valueOf(Phone.PREFERRED_NT_MODE)));
6541 }
fionaxua13278b2018-03-21 00:08:13 -07006542
6543 @Override
6544 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
6545 gid1, String gid2, String plmn, String spn) {
6546 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08006547
6548 final long identity = Binder.clearCallingIdentity();
6549 try {
6550 final Phone phone = getPhone(subId);
6551 if (phone == null) {
6552 loge("setCarrierTestOverride fails with invalid subId: " + subId);
6553 return;
6554 }
6555 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
6556 } finally {
6557 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006558 }
fionaxua13278b2018-03-21 00:08:13 -07006559 }
6560
6561 @Override
6562 public int getCarrierIdListVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07006563 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chend965c8b2018-02-28 15:00:40 -08006564
6565 final long identity = Binder.clearCallingIdentity();
6566 try {
6567 final Phone phone = getPhone(subId);
6568 if (phone == null) {
6569 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
6570 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
6571 }
6572 return phone.getCarrierIdListVersion();
6573 } finally {
6574 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006575 }
fionaxua13278b2018-03-21 00:08:13 -07006576 }
Malcolm Chenf144d942018-08-14 16:00:53 -07006577
6578 @Override
6579 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
6580 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6581 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
6582 return -1;
6583 }
6584
6585 final long identity = Binder.clearCallingIdentity();
6586 try {
6587 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
6588 } finally {
6589 Binder.restoreCallingIdentity(identity);
6590 }
6591 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07006592
6593 @Override
6594 public int getCdmaRoamingMode(int subId) {
6595 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6596 mApp, subId, "getCdmaRoamingMode");
6597
6598 final long identity = Binder.clearCallingIdentity();
6599 try {
6600 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
6601 } finally {
6602 Binder.restoreCallingIdentity(identity);
6603 }
6604 }
6605
6606 @Override
6607 public boolean setCdmaRoamingMode(int subId, int mode) {
6608 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6609 mApp, subId, "setCdmaRoamingMode");
6610
6611 final long identity = Binder.clearCallingIdentity();
6612 try {
6613 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
6614 } finally {
6615 Binder.restoreCallingIdentity(identity);
6616 }
6617 }
6618
6619 @Override
6620 public boolean setCdmaSubscriptionMode(int subId, int mode) {
6621 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6622 mApp, subId, "setCdmaSubscriptionMode");
6623
6624 final long identity = Binder.clearCallingIdentity();
6625 try {
6626 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
6627 } finally {
6628 Binder.restoreCallingIdentity(identity);
6629 }
6630 }
chen xu7ee67862018-10-30 22:27:10 -07006631
sqian2fff4a32018-11-05 14:18:37 -08006632 private void ensureUserRunning(int userId) {
6633 if (!mUserManager.isUserRunning(userId)) {
6634 throw new IllegalStateException("User " + userId + " does not exist or not running");
6635 }
6636 }
6637
6638 /**
6639 * Returns a list of SMS apps on a given user.
6640 *
6641 * Only the shell user (UID 2000 or 0) can call it.
6642 * Target user must be running.
6643 */
6644 @Override
6645 public String[] getSmsApps(int userId) {
6646 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
6647 ensureUserRunning(userId);
6648
6649 final Collection<SmsApplicationData> apps =
6650 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
6651
6652 String[] ret = new String[apps.size()];
6653 int i = 0;
6654 for (SmsApplicationData app : apps) {
6655 ret[i++] = app.mPackageName;
6656 }
6657 return ret;
6658 }
6659
6660 /**
6661 * Returns the default SMS app package name on a given user.
6662 *
6663 * Only the shell user (UID 2000 or 0) can call it.
6664 * Target user must be running.
6665 */
6666 @Override
6667 public String getDefaultSmsApp(int userId) {
6668 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
6669 ensureUserRunning(userId);
6670
6671 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
6672 /* updateIfNeeded= */ true, userId);
6673 return cn == null ? null : cn.getPackageName();
6674 }
6675
6676 /**
6677 * Set a package as the default SMS app on a given user.
6678 *
6679 * Only the shell user (UID 2000 or 0) can call it.
6680 * Target user must be running.
6681 */
6682 @Override
6683 public void setDefaultSmsApp(int userId, String packageName) {
6684 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
6685 ensureUserRunning(userId);
6686
6687 boolean found = false;
6688 for (String pkg : getSmsApps(userId)) {
6689 if (TextUtils.equals(packageName, pkg)) {
6690 found = true;
6691 break;
6692 }
6693 }
6694 if (!found) {
6695 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
6696 }
6697
6698 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
6699 }
6700
chen xu7ee67862018-10-30 22:27:10 -07006701 @Override
sqian65eefe12019-02-22 15:55:18 -08006702 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
sqian04b86072018-11-07 14:02:21 -08006703 String callingPackage) {
sqian03bca152018-12-05 18:48:28 -08006704 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
sqian65eefe12019-02-22 15:55:18 -08006705 mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) {
sqian03bca152018-12-05 18:48:28 -08006706 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6707 }
6708 final long identity = Binder.clearCallingIdentity();
6709 try {
sqian991b35e2018-12-12 16:48:18 -08006710 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
6711 for (Phone phone: PhoneFactory.getPhones()) {
6712 if (phone.getEmergencyNumberTracker() != null
6713 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
6714 emergencyNumberListInternal.put(
6715 phone.getSubId(),
6716 phone.getEmergencyNumberTracker().getEmergencyNumberList());
6717 }
sqian03bca152018-12-05 18:48:28 -08006718 }
sqian991b35e2018-12-12 16:48:18 -08006719 return emergencyNumberListInternal;
sqian03bca152018-12-05 18:48:28 -08006720 } finally {
6721 Binder.restoreCallingIdentity(identity);
6722 }
sqian04b86072018-11-07 14:02:21 -08006723 }
6724
6725 @Override
sqian65eefe12019-02-22 15:55:18 -08006726 public boolean isEmergencyNumber(String number, boolean exactMatch) {
sqian03bca152018-12-05 18:48:28 -08006727 final Phone defaultPhone = getDefaultPhone();
6728 if (!exactMatch) {
6729 TelephonyPermissions
6730 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian65eefe12019-02-22 15:55:18 -08006731 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian03bca152018-12-05 18:48:28 -08006732 }
6733 final long identity = Binder.clearCallingIdentity();
6734 try {
sqian991b35e2018-12-12 16:48:18 -08006735 for (Phone phone: PhoneFactory.getPhones()) {
6736 if (phone.getEmergencyNumberTracker() != null
6737 && phone.getEmergencyNumberTracker() != null) {
6738 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
6739 number, exactMatch)) {
6740 return true;
sqian03bca152018-12-05 18:48:28 -08006741 }
6742 }
sqian03bca152018-12-05 18:48:28 -08006743 }
6744 return false;
6745 } finally {
6746 Binder.restoreCallingIdentity(identity);
6747 }
6748 }
6749
sqian9d4df8b2019-01-15 18:32:07 -08006750 /**
6751 * Update emergency number list for test mode.
6752 */
6753 @Override
6754 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
6755 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6756 "updateEmergencyNumberListTestMode");
6757
6758 final long identity = Binder.clearCallingIdentity();
6759 try {
6760 for (Phone phone: PhoneFactory.getPhones()) {
6761 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6762 if (tracker != null) {
6763 tracker.executeEmergencyNumberTestModeCommand(action, num);
6764 }
6765 }
6766 } finally {
6767 Binder.restoreCallingIdentity(identity);
6768 }
6769 }
6770
6771 /**
6772 * Get the full emergency number list for test mode.
6773 */
6774 @Override
6775 public List<String> getEmergencyNumberListTestMode() {
6776 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6777 "getEmergencyNumberListTestMode");
6778
6779 final long identity = Binder.clearCallingIdentity();
6780 try {
6781 Set<String> emergencyNumbers = new HashSet<>();
6782 for (Phone phone: PhoneFactory.getPhones()) {
6783 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6784 if (tracker != null) {
6785 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
6786 emergencyNumbers.add(num.getNumber());
6787 }
6788 }
6789 }
6790 return new ArrayList<>(emergencyNumbers);
6791 } finally {
6792 Binder.restoreCallingIdentity(identity);
6793 }
6794 }
6795
sqian04b86072018-11-07 14:02:21 -08006796 @Override
chen xu7ee67862018-10-30 22:27:10 -07006797 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
6798 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
6799 Phone phone = getPhone(subId);
6800 if (phone == null) {
6801 return null;
6802 }
6803 final long identity = Binder.clearCallingIdentity();
6804 try {
6805 UiccProfile profile = UiccController.getInstance()
6806 .getUiccProfileForPhone(phone.getPhoneId());
6807 if (profile != null) {
6808 return profile.getCertsFromCarrierPrivilegeAccessRules();
6809 }
6810 } finally {
6811 Binder.restoreCallingIdentity(identity);
6812 }
6813 return null;
6814 }
Malcolm Chen509b5b72019-01-15 20:22:16 -08006815
6816 /**
6817 * Enable or disable a modem stack.
6818 */
6819 @Override
6820 public boolean enableModemForSlot(int slotIndex, boolean enable) {
6821 enforceModifyPermission();
6822
6823 final long identity = Binder.clearCallingIdentity();
6824 try {
6825 Phone phone = PhoneFactory.getPhone(slotIndex);
6826 if (phone == null) {
6827 return false;
6828 } else {
6829 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
6830 }
6831 } finally {
6832 Binder.restoreCallingIdentity(identity);
6833 }
6834 }
Micheled3107c52018-12-21 15:00:11 -08006835
Malcolm Chen33f55e12019-03-27 18:34:05 -07006836 /**
6837 * Whether a modem stack is enabled or not.
6838 */
6839 @Override
6840 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage) {
6841 Phone phone = PhoneFactory.getPhone(slotIndex);
6842 if (phone == null) return false;
6843
6844 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6845 mApp, phone.getSubId(), callingPackage, "isModemEnabledForSlot")) {
6846 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6847 }
6848
6849 final long identity = Binder.clearCallingIdentity();
6850 try {
Nazanin Bakhshi1f78d7d2019-04-29 17:29:44 -07006851 try {
6852 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
6853 } catch (NoSuchElementException ex) {
6854 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
6855 }
Malcolm Chen33f55e12019-03-27 18:34:05 -07006856 } finally {
6857 Binder.restoreCallingIdentity(identity);
6858 }
6859 }
6860
Micheled3107c52018-12-21 15:00:11 -08006861 @Override
Michele2fb0f222019-03-19 14:58:42 -07006862 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Micheled3107c52018-12-21 15:00:11 -08006863 enforceModifyPermission();
6864
6865 final long identity = Binder.clearCallingIdentity();
6866 try {
6867 mTelephonySharedPreferences.edit()
Michele2fb0f222019-03-19 14:58:42 -07006868 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Micheled3107c52018-12-21 15:00:11 -08006869 .commit();
6870 } finally {
6871 Binder.restoreCallingIdentity(identity);
6872 }
6873 }
6874
6875 @Override
Michele2fb0f222019-03-19 14:58:42 -07006876 @TelephonyManager.IsMultiSimSupportedResult
6877 public int isMultiSimSupported(String callingPackage) {
Michelebcb01bc2019-02-04 11:36:23 -08006878 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Michele2fb0f222019-03-19 14:58:42 -07006879 getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) {
6880 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michelebcb01bc2019-02-04 11:36:23 -08006881 }
Micheled3107c52018-12-21 15:00:11 -08006882
6883 final long identity = Binder.clearCallingIdentity();
6884 try {
Michele2fb0f222019-03-19 14:58:42 -07006885 return isMultiSimSupportedInternal();
Micheled3107c52018-12-21 15:00:11 -08006886 } finally {
6887 Binder.restoreCallingIdentity(identity);
6888 }
6889 }
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006890
Michele2fb0f222019-03-19 14:58:42 -07006891 @TelephonyManager.IsMultiSimSupportedResult
6892 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08006893 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
6894 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
6895 if (numPhysicalSlots < 2) {
Michele2fb0f222019-03-19 14:58:42 -07006896 loge("isMultiSimSupportedInternal: requires at least 2 cards");
6897 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006898 }
6899 // Check if the hardware supports multisim functionality. If usage of multisim is not
6900 // supported by the modem, indicate that it is restricted.
6901 PhoneCapability staticCapability =
6902 mPhoneConfigurationManager.getStaticPhoneCapability();
6903 if (staticCapability == null) {
Michele2fb0f222019-03-19 14:58:42 -07006904 loge("isMultiSimSupportedInternal: no static configuration available");
6905 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006906 }
6907 if (staticCapability.logicalModemList.size() < 2) {
Michele2fb0f222019-03-19 14:58:42 -07006908 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
6909 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006910 }
6911 // Check if support of multiple SIMs is restricted by carrier
6912 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele2fb0f222019-03-19 14:58:42 -07006913 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08006914 }
6915
Michele2fb0f222019-03-19 14:58:42 -07006916 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08006917 }
6918
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006919 /**
6920 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi814dc222019-03-01 11:56:08 -08006921 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
6922 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
6923 * or carrier privileges
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006924 * @param numOfSims number of active sims we want to switch to
6925 */
6926 @Override
6927 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi814dc222019-03-01 11:56:08 -08006928 if (numOfSims == 1) {
6929 enforceModifyPermission();
6930 } else {
6931 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6932 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
6933 }
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006934 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08006935
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006936 try {
Michele30b57b22019-03-01 12:01:14 -08006937 //only proceed if multi-sim is not restricted
Michele2fb0f222019-03-19 14:58:42 -07006938 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08006939 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
6940 return;
6941 }
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006942 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
6943 } finally {
6944 Binder.restoreCallingIdentity(identity);
6945 }
6946 }
6947
6948 /**
Nazanin Bakhshicd417af2019-01-30 10:52:09 -08006949 * Get whether reboot is required or not after making changes to modem configurations.
Nazanin Bakhshi4a68f5f2019-02-08 14:31:19 -08006950 * Return value defaults to true
Nazanin Bakhshicd417af2019-01-30 10:52:09 -08006951 */
6952 @Override
6953 public boolean isRebootRequiredForModemConfigChange() {
6954 enforceReadPrivilegedPermission("isRebootRequiredForModemConfigChange");
6955 final long identity = Binder.clearCallingIdentity();
6956 try {
6957 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
6958 } finally {
6959 Binder.restoreCallingIdentity(identity);
6960 }
6961 }
6962
Pengquan Meng92d253b2019-02-06 11:12:53 -08006963 private void updateModemStateMetrics() {
6964 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
6965 // TODO: check the state for each modem if the api is ready.
6966 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
6967 }
6968
Pengquan Meng3aceaec2019-01-23 11:16:29 -08006969 @Override
6970 public int[] getSlotsMapping() {
6971 enforceReadPrivilegedPermission("getSlotsMapping");
6972
6973 final long identity = Binder.clearCallingIdentity();
6974 try {
6975 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
6976 // All logical slots should have a mapping to a physical slot.
6977 int[] logicalSlotsMapping = new int[phoneCount];
6978 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
6979 for (int i = 0; i < slotInfos.length; i++) {
6980 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
6981 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
6982 }
6983 }
6984 return logicalSlotsMapping;
6985 } finally {
6986 Binder.restoreCallingIdentity(identity);
6987 }
6988 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08006989
6990 /**
6991 * Get the IRadio HAL Version
6992 */
6993 @Override
6994 public int getRadioHalVersion() {
6995 Phone phone = getDefaultPhone();
6996 if (phone == null) return -1;
6997 HalVersion hv = phone.getHalVersion();
6998 if (hv.equals(HalVersion.UNKNOWN)) return -1;
6999 return hv.major * 100 + hv.minor;
7000 }
Malcolm Chen460810d2019-04-10 18:25:07 -07007001
7002 /**
Malcolm Chen29739692019-04-18 13:51:02 -07007003 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7004 * corresponding network requests on a subId.
7005 *
7006 * Data is enabled if:
Malcolm Chen460810d2019-04-10 18:25:07 -07007007 * 1) user data is turned on, or
Malcolm Chen29739692019-04-18 13:51:02 -07007008 * 2) APN is un-metered for this subscription, or
7009 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
7010 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on.
7011 *
7012 * @return whether data is allowed for a apn type.
7013 *
7014 * @hide
Malcolm Chen460810d2019-04-10 18:25:07 -07007015 */
7016 @Override
Malcolm Chen29739692019-04-18 13:51:02 -07007017 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Malcolm Chen460810d2019-04-10 18:25:07 -07007018 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Malcolm Chen29739692019-04-18 13:51:02 -07007019 mApp, subId, callingPackage, "isDataEnabledForApn")) {
7020 throw new SecurityException("Needs READ_PHONE_STATE for isDataEnabledForApn");
Malcolm Chen460810d2019-04-10 18:25:07 -07007021 }
7022
7023 // Now that all security checks passes, perform the operation as ourselves.
7024 final long identity = Binder.clearCallingIdentity();
7025 try {
7026 Phone phone = getPhone(subId);
7027 if (phone == null) return false;
7028
Jack Yu40306fc2019-05-13 16:54:09 -07007029 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chen29739692019-04-18 13:51:02 -07007030 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7031 } finally {
7032 Binder.restoreCallingIdentity(identity);
7033 }
7034 }
7035
7036 @Override
Jack Yu40306fc2019-05-13 16:54:09 -07007037 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chen29739692019-04-18 13:51:02 -07007038 enforceReadPrivilegedPermission("isApnMetered");
7039
7040 // Now that all security checks passes, perform the operation as ourselves.
7041 final long identity = Binder.clearCallingIdentity();
7042 try {
7043 Phone phone = getPhone(subId);
7044 if (phone == null) return true; // By default return true.
7045
Jack Yu40306fc2019-05-13 16:54:09 -07007046 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chen460810d2019-04-10 18:25:07 -07007047 } finally {
7048 Binder.restoreCallingIdentity(identity);
7049 }
7050 }
chen xu7bc8e072019-05-28 15:20:57 -07007051
7052 @Override
Brad Ebinger5ff97f62019-04-23 16:31:13 -07007053 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
7054 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
7055 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
7056 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
7057 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
7058 }
7059 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
7060 Intent intent = new Intent();
7061 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
7062 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7063 // Bring up choose default SMS subscription dialog right now
7064 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
7065 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
7066 mApp.startActivity(intent);
7067 }
7068
7069 @Override
chen xu7bc8e072019-05-28 15:20:57 -07007070 public String getMmsUAProfUrl(int subId) {
7071 //TODO investigate if this API should require proper permission check in R b/133791609
7072 final long identity = Binder.clearCallingIdentity();
7073 try {
7074 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7075 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
7076 } finally {
7077 Binder.restoreCallingIdentity(identity);
7078 }
7079 }
7080
7081 @Override
7082 public String getMmsUserAgent(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);
7088 } finally {
7089 Binder.restoreCallingIdentity(identity);
7090 }
7091 }
Jack Yuea3bebe2019-05-28 16:12:25 -07007092
7093 @Override
7094 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
7095 enforceModifyPermission();
7096
7097 // Now that all security checks passes, perform the operation as ourselves.
7098 final long identity = Binder.clearCallingIdentity();
7099 try {
7100 Phone phone = getPhone(subId);
7101 if (phone == null) return false;
7102
7103 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
7104 } finally {
7105 Binder.restoreCallingIdentity(identity);
7106 }
7107 }
7108
7109 @Override
7110 public boolean isDataAllowedInVoiceCall(int subId) {
7111 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
7112
7113 // Now that all security checks passes, perform the operation as ourselves.
7114 final long identity = Binder.clearCallingIdentity();
7115 try {
7116 Phone phone = getPhone(subId);
7117 if (phone == null) return false;
7118
7119 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
7120 } finally {
7121 Binder.restoreCallingIdentity(identity);
7122 }
7123 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007124}