blob: 87b2033462c829a552e667cf2d124600edf02e64 [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() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001875 final long identity = Binder.clearCallingIdentity();
1876 try {
Nathan Harolde037c472019-06-26 00:41:07 +00001877 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Malcolm Chend965c8b2018-02-28 15:00:40 -08001878 if (phone != null) {
1879 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1880 } else {
1881 return PhoneConstantConversions.convertDataState(
1882 PhoneConstants.DataState.DISCONNECTED);
1883 }
1884 } finally {
1885 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001886 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001887 }
1888
Sanket Padawe356d7632015-06-22 14:03:32 -07001889 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001890 public int getDataActivity() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001891 final long identity = Binder.clearCallingIdentity();
1892 try {
Nathan Harolde037c472019-06-26 00:41:07 +00001893 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Malcolm Chend965c8b2018-02-28 15:00:40 -08001894 if (phone != null) {
1895 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1896 } else {
1897 return TelephonyManager.DATA_ACTIVITY_NONE;
1898 }
1899 } finally {
1900 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001901 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001902 }
1903
1904 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001905 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001906 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001907 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08001908
1909 LocationAccessPolicy.LocationPermissionResult locationResult =
1910 LocationAccessPolicy.checkLocationPermission(mApp,
1911 new LocationAccessPolicy.LocationPermissionQuery.Builder()
1912 .setCallingPackage(callingPackage)
1913 .setCallingPid(Binder.getCallingPid())
1914 .setCallingUid(Binder.getCallingUid())
1915 .setMethod("getCellLocation")
1916 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
1917 .build());
1918 switch (locationResult) {
1919 case DENIED_HARD:
1920 throw new SecurityException("Not allowed to access cell location");
1921 case DENIED_SOFT:
1922 return new Bundle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001923 }
1924
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001925 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08001926 final long identity = Binder.clearCallingIdentity();
1927 try {
1928 if (DBG_LOC) log("getCellLocation: is active user");
1929 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001930 int subId = mSubscriptionController.getDefaultDataSubId();
1931 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1932 cl.fillInNotifierBundle(data);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001933 return data;
1934 } finally {
1935 Binder.restoreCallingIdentity(identity);
1936 }
Svetoslav64fad262015-04-14 14:35:21 -07001937 }
1938
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001939 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001940 public String getNetworkCountryIsoForPhone(int phoneId) {
1941 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1942 // registered cell info, so return a NULL country instead.
1943 final long identity = Binder.clearCallingIdentity();
1944 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001945 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1946 // Get default phone in this case.
1947 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1948 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001949 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001950 // Todo: fix this when we can get the actual cellular network info when the device
1951 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001952 if (TelephonyManager.NETWORK_TYPE_IWLAN
1953 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1954 return "";
1955 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001956 Phone phone = PhoneFactory.getPhone(phoneId);
1957 if (phone != null) {
1958 ServiceStateTracker sst = phone.getServiceStateTracker();
1959 if (sst != null) {
1960 LocaleTracker lt = sst.getLocaleTracker();
1961 if (lt != null) {
1962 return lt.getCurrentCountry();
1963 }
1964 }
1965 }
1966 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001967 } finally {
1968 Binder.restoreCallingIdentity(identity);
1969 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001970 }
1971
1972 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001973 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001974 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001975 }
1976
Sanket Padawe356d7632015-06-22 14:03:32 -07001977 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001978 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001979 mApp.enforceCallingOrSelfPermission(
1980 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001981
1982 final long identity = Binder.clearCallingIdentity();
1983 try {
1984 final Phone phone = getPhone(subId);
1985 if (phone != null) {
1986 phone.enableLocationUpdates();
1987 }
1988 } finally {
1989 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001990 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001991 }
1992
1993 @Override
1994 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001995 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001996 }
1997
Sanket Padawe356d7632015-06-22 14:03:32 -07001998 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001999 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002000 mApp.enforceCallingOrSelfPermission(
2001 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002002
2003 final long identity = Binder.clearCallingIdentity();
2004 try {
2005 final Phone phone = getPhone(subId);
2006 if (phone != null) {
2007 phone.disableLocationUpdates();
2008 }
2009 } finally {
2010 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002011 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002012 }
2013
Nathan Harold31d7ff32018-10-15 20:20:30 -07002014 /**
2015 * Returns the target SDK version number for a given package name.
2016 *
2017 * @return target SDK if the package is found or INT_MAX.
2018 */
2019 private int getTargetSdk(String packageName) {
2020 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002021 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(
2022 packageName, 0);
Nathan Harold31d7ff32018-10-15 20:20:30 -07002023 if (ai != null) return ai.targetSdkVersion;
2024 } catch (PackageManager.NameNotFoundException unexpected) {
2025 }
2026 return Integer.MAX_VALUE;
2027 }
2028
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002029 @Override
2030 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07002031 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
2032 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002033 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2034 throw new SecurityException(
2035 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2036 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002037
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002038 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
2039 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2040 return null;
2041 }
Svetoslav64fad262015-04-14 14:35:21 -07002042
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002043 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002044
Nathan Haroldf180aac2018-06-01 18:43:55 -07002045 List<CellInfo> info = getAllCellInfo(callingPackage);
2046 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002047
Nathan Haroldf180aac2018-06-01 18:43:55 -07002048 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2049 for (CellInfo ci : info) {
2050 if (ci instanceof CellInfoGsm) {
2051 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2052 } else if (ci instanceof CellInfoWcdma) {
2053 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2054 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002055 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002056 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002057 }
2058
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002059 private List<CellInfo> getCachedCellInfo() {
2060 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2061 for (Phone phone : PhoneFactory.getPhones()) {
2062 List<CellInfo> info = phone.getAllCellInfo();
2063 if (info != null) cellInfos.addAll(info);
2064 }
2065 return cellInfos;
2066 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002067
2068 @Override
Svetoslav64fad262015-04-14 14:35:21 -07002069 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002070 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002071 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002072
2073 LocationAccessPolicy.LocationPermissionResult locationResult =
2074 LocationAccessPolicy.checkLocationPermission(mApp,
2075 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2076 .setCallingPackage(callingPackage)
2077 .setCallingPid(Binder.getCallingPid())
2078 .setCallingUid(Binder.getCallingUid())
2079 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002080 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002081 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2082 .build());
2083 switch (locationResult) {
2084 case DENIED_HARD:
2085 throw new SecurityException("Not allowed to access cell info");
2086 case DENIED_SOFT:
2087 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002088 }
2089
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002090 final int targetSdk = getTargetSdk(callingPackage);
2091 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2092 return getCachedCellInfo();
2093 }
2094
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002095 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002096 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08002097 final long identity = Binder.clearCallingIdentity();
2098 try {
2099 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2100 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002101 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002102 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002103 if (info != null) cellInfos.addAll(info);
2104 }
2105 return cellInfos;
2106 } finally {
2107 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002108 }
2109 }
2110
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002111 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002112 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2113 requestCellInfoUpdateInternal(
2114 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2115 }
2116
2117 @Override
2118 public void requestCellInfoUpdateWithWorkSource(
2119 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2120 enforceModifyPermission();
2121 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2122 }
2123
2124 private void requestCellInfoUpdateInternal(
2125 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002126 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002127 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002128
2129 LocationAccessPolicy.LocationPermissionResult locationResult =
2130 LocationAccessPolicy.checkLocationPermission(mApp,
2131 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2132 .setCallingPackage(callingPackage)
2133 .setCallingPid(Binder.getCallingPid())
2134 .setCallingUid(Binder.getCallingUid())
2135 .setMethod("requestCellInfoUpdate")
2136 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2137 .build());
2138 switch (locationResult) {
2139 case DENIED_HARD:
2140 throw new SecurityException("Not allowed to access cell info");
2141 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002142 try {
2143 cb.onCellInfo(new ArrayList<CellInfo>());
2144 } catch (RemoteException re) {
2145 // Drop without consequences
2146 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002147 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002148 }
2149
Nathan Harolda939a962019-05-09 10:13:47 -07002150
2151 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002152 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2153
2154 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2155 }
2156
2157 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002158 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002159 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002160 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08002161
2162 final long identity = Binder.clearCallingIdentity();
2163 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002164 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002165 } finally {
2166 Binder.restoreCallingIdentity(identity);
2167 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002168 }
2169
Shishir Agrawala9f32182016-04-12 12:00:16 -07002170 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002171 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002172 Phone phone = PhoneFactory.getPhone(slotIndex);
2173 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002174 return null;
2175 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002176 int subId = phone.getSubId();
2177 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2178 mApp, subId, callingPackage, "getImeiForSlot")) {
2179 return null;
2180 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002181
2182 final long identity = Binder.clearCallingIdentity();
2183 try {
2184 return phone.getImei();
2185 } finally {
2186 Binder.restoreCallingIdentity(identity);
2187 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002188 }
2189
2190 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002191 public String getTypeAllocationCodeForSlot(int slotIndex) {
2192 Phone phone = PhoneFactory.getPhone(slotIndex);
2193 String tac = null;
2194 if (phone != null) {
2195 String imei = phone.getImei();
2196 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2197 }
2198 return tac;
2199 }
2200
2201 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002202 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002203 Phone phone = PhoneFactory.getPhone(slotIndex);
2204 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002205 return null;
2206 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002207
Jeff Davidson913390f2018-02-23 17:11:49 -08002208 int subId = phone.getSubId();
2209 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2210 mApp, subId, callingPackage, "getMeidForSlot")) {
2211 return null;
2212 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002213
2214 final long identity = Binder.clearCallingIdentity();
2215 try {
2216 return phone.getMeid();
2217 } finally {
2218 Binder.restoreCallingIdentity(identity);
2219 }
Jack Yu2af8d712017-03-15 17:14:14 -07002220 }
2221
2222 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002223 public String getManufacturerCodeForSlot(int slotIndex) {
2224 Phone phone = PhoneFactory.getPhone(slotIndex);
2225 String manufacturerCode = null;
2226 if (phone != null) {
2227 String meid = phone.getMeid();
2228 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2229 }
2230 return manufacturerCode;
2231 }
2232
2233 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002234 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002235 Phone phone = PhoneFactory.getPhone(slotIndex);
2236 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002237 return null;
2238 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002239 int subId = phone.getSubId();
2240 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2241 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2242 return null;
2243 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002244
2245 final long identity = Binder.clearCallingIdentity();
2246 try {
2247 return phone.getDeviceSvn();
2248 } finally {
2249 Binder.restoreCallingIdentity(identity);
2250 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002251 }
2252
fionaxu43304da2017-11-27 22:51:16 -08002253 @Override
2254 public int getSubscriptionCarrierId(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002255 final long identity = Binder.clearCallingIdentity();
2256 try {
2257 final Phone phone = getPhone(subId);
2258 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2259 } finally {
2260 Binder.restoreCallingIdentity(identity);
2261 }
fionaxu43304da2017-11-27 22:51:16 -08002262 }
2263
2264 @Override
2265 public String getSubscriptionCarrierName(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002266 final long identity = Binder.clearCallingIdentity();
2267 try {
2268 final Phone phone = getPhone(subId);
2269 return phone == null ? null : phone.getCarrierName();
2270 } finally {
2271 Binder.restoreCallingIdentity(identity);
2272 }
fionaxu43304da2017-11-27 22:51:16 -08002273 }
2274
calvinpaneed9ae82018-11-01 19:43:06 +08002275 @Override
chen xua31f22b2019-03-06 15:28:50 -08002276 public int getSubscriptionSpecificCarrierId(int subId) {
chen xuc93cc282018-11-04 17:17:00 -08002277 final long identity = Binder.clearCallingIdentity();
2278 try {
2279 final Phone phone = getPhone(subId);
2280 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xua31f22b2019-03-06 15:28:50 -08002281 : phone.getSpecificCarrierId();
chen xuc93cc282018-11-04 17:17:00 -08002282 } finally {
2283 Binder.restoreCallingIdentity(identity);
2284 }
2285 }
2286
2287 @Override
chen xua31f22b2019-03-06 15:28:50 -08002288 public String getSubscriptionSpecificCarrierName(int subId) {
chen xuc93cc282018-11-04 17:17:00 -08002289 final long identity = Binder.clearCallingIdentity();
2290 try {
2291 final Phone phone = getPhone(subId);
chen xua31f22b2019-03-06 15:28:50 -08002292 return phone == null ? null : phone.getSpecificCarrierName();
chen xuc93cc282018-11-04 17:17:00 -08002293 } finally {
2294 Binder.restoreCallingIdentity(identity);
2295 }
2296 }
2297
chen xu02581692018-11-11 19:03:44 -08002298 @Override
chen xu4ca4e692018-12-06 22:10:03 -08002299 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2300 if (!isSubscriptionMccMnc) {
2301 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2302 }
chen xu02581692018-11-11 19:03:44 -08002303 final Phone phone = PhoneFactory.getPhone(slotIndex);
2304 if (phone == null) {
2305 return TelephonyManager.UNKNOWN_CARRIER_ID;
2306 }
2307 final long identity = Binder.clearCallingIdentity();
2308 try {
2309 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2310 } finally {
2311 Binder.restoreCallingIdentity(identity);
2312 }
2313 }
2314
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002315 //
2316 // Internal helper methods.
2317 //
2318
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002319 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002320 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2321 *
2322 * @throws SecurityException if the caller does not have the required permission
2323 */
2324 private void enforceModifyPermission() {
2325 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2326 }
2327
2328 /**
2329 * Make sure the caller has the CALL_PHONE permission.
2330 *
2331 * @throws SecurityException if the caller does not have the required permission
2332 */
2333 private void enforceCallPermission() {
2334 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2335 }
2336
Stuart Scott8eef64f2015-04-08 15:13:54 -07002337 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002338 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002339 "ConnectivityService");
2340 }
2341
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002342 private String createTelUrl(String number) {
2343 if (TextUtils.isEmpty(number)) {
2344 return null;
2345 }
2346
Jake Hambye994d462014-02-03 13:10:13 -08002347 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002348 }
2349
Ihab Awadf9e92732013-12-05 18:02:52 -08002350 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002351 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2352 }
2353
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002354 private static void logv(String msg) {
2355 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2356 }
2357
Ihab Awadf9e92732013-12-05 18:02:52 -08002358 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002359 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2360 }
2361
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002362 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002363 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002364 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002365 }
2366
Sanket Padawe356d7632015-06-22 14:03:32 -07002367 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002368 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002369 final long identity = Binder.clearCallingIdentity();
2370 try {
2371 final Phone phone = PhoneFactory.getPhone(slotIndex);
2372 if (phone == null) {
2373 return PhoneConstants.PHONE_TYPE_NONE;
2374 } else {
2375 return phone.getPhoneType();
2376 }
2377 } finally {
2378 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002379 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002380 }
2381
2382 /**
2383 * Returns the CDMA ERI icon index to display
2384 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002385 @Override
2386 public int getCdmaEriIconIndex(String callingPackage) {
2387 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002388 }
2389
Sanket Padawe356d7632015-06-22 14:03:32 -07002390 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002391 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002392 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002393 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002394 return -1;
2395 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002396
2397 final long identity = Binder.clearCallingIdentity();
2398 try {
2399 final Phone phone = getPhone(subId);
2400 if (phone != null) {
2401 return phone.getCdmaEriIconIndex();
2402 } else {
2403 return -1;
2404 }
2405 } finally {
2406 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002407 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002408 }
2409
2410 /**
2411 * Returns the CDMA ERI icon mode,
2412 * 0 - ON
2413 * 1 - FLASHING
2414 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002415 @Override
2416 public int getCdmaEriIconMode(String callingPackage) {
2417 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002418 }
2419
Sanket Padawe356d7632015-06-22 14:03:32 -07002420 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002421 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002422 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002423 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002424 return -1;
2425 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002426
2427 final long identity = Binder.clearCallingIdentity();
2428 try {
2429 final Phone phone = getPhone(subId);
2430 if (phone != null) {
2431 return phone.getCdmaEriIconMode();
2432 } else {
2433 return -1;
2434 }
2435 } finally {
2436 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002437 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002438 }
2439
2440 /**
2441 * Returns the CDMA ERI text,
2442 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002443 @Override
2444 public String getCdmaEriText(String callingPackage) {
2445 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002446 }
2447
Sanket Padawe356d7632015-06-22 14:03:32 -07002448 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002449 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002450 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002451 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002452 return null;
2453 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002454
2455 final long identity = Binder.clearCallingIdentity();
2456 try {
2457 final Phone phone = getPhone(subId);
2458 if (phone != null) {
2459 return phone.getCdmaEriText();
2460 } else {
2461 return null;
2462 }
2463 } finally {
2464 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002465 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002466 }
2467
2468 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002469 * Returns the CDMA MDN.
2470 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002471 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002472 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002473 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2474 mApp, subId, "getCdmaMdn");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002475
2476 final long identity = Binder.clearCallingIdentity();
2477 try {
2478 final Phone phone = getPhone(subId);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002479 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002480 return phone.getLine1Number();
2481 } else {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002482 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002483 return null;
2484 }
2485 } finally {
2486 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002487 }
2488 }
2489
2490 /**
2491 * Returns the CDMA MIN.
2492 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002493 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002494 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002495 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2496 mApp, subId, "getCdmaMin");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002497
2498 final long identity = Binder.clearCallingIdentity();
2499 try {
2500 final Phone phone = getPhone(subId);
2501 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2502 return phone.getCdmaMin();
2503 } else {
2504 return null;
2505 }
2506 } finally {
2507 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002508 }
2509 }
2510
Hall Liud892bec2018-11-30 14:51:45 -08002511 @Override
2512 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2513 INumberVerificationCallback callback, String callingPackage) {
2514 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2515 != PERMISSION_GRANTED) {
2516 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2517 }
2518 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2519
2520 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2521 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2522 throw new SecurityException("Calling package must be configured in the device config");
2523 }
2524
2525 if (range == null) {
2526 throw new NullPointerException("Range must be non-null");
2527 }
2528
2529 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002530 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002531
2532 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2533 }
2534
Junda Liuca05d5d2014-08-14 22:36:34 -07002535 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002536 * Returns true if CDMA provisioning needs to run.
2537 */
2538 public boolean needsOtaServiceProvisioning() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002539 final long identity = Binder.clearCallingIdentity();
2540 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002541 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chend965c8b2018-02-28 15:00:40 -08002542 } finally {
2543 Binder.restoreCallingIdentity(identity);
2544 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002545 }
2546
2547 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002548 * Sets the voice mail number of a given subId.
2549 */
2550 @Override
2551 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002552 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002553
2554 final long identity = Binder.clearCallingIdentity();
2555 try {
2556 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2557 new Pair<String, String>(alphaTag, number), new Integer(subId));
2558 return success;
2559 } finally {
2560 Binder.restoreCallingIdentity(identity);
2561 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002562 }
2563
Ta-wei Yen87c49842016-05-13 21:19:52 -07002564 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002565 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2566 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002567 String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002568 if (!TextUtils.equals(callingPackage, systemDialer)) {
2569 throw new SecurityException("caller must be system dialer");
2570 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002571
2572 final long identity = Binder.clearCallingIdentity();
2573 try {
2574 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2575 if (phoneAccountHandle == null) {
2576 return null;
2577 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002578 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002579 } finally {
2580 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002581 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002582 }
2583
2584 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002585 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002586 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002587 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002588 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002589 return null;
2590 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002591
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002592 final long identity = Binder.clearCallingIdentity();
2593 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002594 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002595 } finally {
2596 Binder.restoreCallingIdentity(identity);
2597 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002598 }
2599
2600 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002601 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2602 VisualVoicemailSmsFilterSettings settings) {
2603 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002604
2605 final long identity = Binder.clearCallingIdentity();
2606 try {
2607 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002608 mApp, callingPackage, subId, settings);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002609 } finally {
2610 Binder.restoreCallingIdentity(identity);
2611 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002612 }
2613
2614 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002615 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2616 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002617
2618 final long identity = Binder.clearCallingIdentity();
2619 try {
2620 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002621 mApp, callingPackage, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002622 } finally {
2623 Binder.restoreCallingIdentity(identity);
2624 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002625 }
2626
2627 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002628 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2629 String callingPackage, int subId) {
2630 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002631
2632 final long identity = Binder.clearCallingIdentity();
2633 try {
2634 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002635 mApp, callingPackage, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002636 } finally {
2637 Binder.restoreCallingIdentity(identity);
2638 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002639 }
2640
2641 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002642 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002643 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002644
2645 final long identity = Binder.clearCallingIdentity();
2646 try {
2647 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002648 mApp, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002649 } finally {
2650 Binder.restoreCallingIdentity(identity);
2651 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002652 }
2653
2654 @Override
2655 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2656 String number, int port, String text, PendingIntent sentIntent) {
2657 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002658 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002659 enforceSendSmsPermission();
Amit Mahajan716e76c2019-05-13 13:48:32 -07002660 SmsController smsController = PhoneFactory.getSmsController();
2661 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
2662 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002663 }
Amit Mahajan716e76c2019-05-13 13:48:32 -07002664
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002665 /**
fionaxu0152e512016-11-14 13:36:14 -08002666 * Sets the voice activation state of a given subId.
2667 */
2668 @Override
2669 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002670 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2671 mApp, subId, "setVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002672
2673 final long identity = Binder.clearCallingIdentity();
2674 try {
2675 final Phone phone = getPhone(subId);
2676 if (phone != null) {
2677 phone.setVoiceActivationState(activationState);
2678 } else {
2679 loge("setVoiceActivationState fails with invalid subId: " + subId);
2680 }
2681 } finally {
2682 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002683 }
2684 }
2685
2686 /**
2687 * Sets the data activation state of a given subId.
2688 */
2689 @Override
2690 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002691 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2692 mApp, subId, "setDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002693
2694 final long identity = Binder.clearCallingIdentity();
2695 try {
2696 final Phone phone = getPhone(subId);
2697 if (phone != null) {
2698 phone.setDataActivationState(activationState);
2699 } else {
2700 loge("setVoiceActivationState fails with invalid subId: " + subId);
2701 }
2702 } finally {
2703 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002704 }
2705 }
2706
2707 /**
2708 * Returns the voice activation state of a given subId.
2709 */
2710 @Override
2711 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002712 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002713
fionaxu0152e512016-11-14 13:36:14 -08002714 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002715 final long identity = Binder.clearCallingIdentity();
2716 try {
2717 if (phone != null) {
2718 return phone.getVoiceActivationState();
2719 } else {
2720 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2721 }
2722 } finally {
2723 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002724 }
2725 }
2726
2727 /**
2728 * Returns the data activation state of a given subId.
2729 */
2730 @Override
2731 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002732 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002733
fionaxu0152e512016-11-14 13:36:14 -08002734 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002735 final long identity = Binder.clearCallingIdentity();
2736 try {
2737 if (phone != null) {
2738 return phone.getDataActivationState();
2739 } else {
2740 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2741 }
2742 } finally {
2743 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002744 }
2745 }
2746
2747 /**
Wink Saville36469e72014-06-11 15:17:00 -07002748 * Returns the unread count of voicemails for a subId
2749 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002750 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002751 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2752 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2753 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2754 return 0;
2755 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002756 final long identity = Binder.clearCallingIdentity();
2757 try {
2758 final Phone phone = getPhone(subId);
2759 if (phone != null) {
2760 return phone.getVoiceMessageCount();
2761 } else {
2762 return 0;
2763 }
2764 } finally {
2765 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002766 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002767 }
2768
2769 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002770 * returns true, if the device is in a state where both voice and data
2771 * are supported simultaneously. This can change based on location or network condition.
2772 */
2773 @Override
2774 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002775 final long identity = Binder.clearCallingIdentity();
2776 try {
2777 final Phone phone = getPhone(subId);
2778 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2779 } finally {
2780 Binder.restoreCallingIdentity(identity);
2781 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002782 }
2783
2784 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002785 * Send the dialer code if called from the current default dialer or the caller has
2786 * carrier privilege.
2787 * @param inputCode The dialer code to send
2788 */
2789 @Override
2790 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002791 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002792 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002793 String defaultDialer = TelecomManager.from(defaultPhone.getContext())
2794 .getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002795 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002796 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2797 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002798 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002799
2800 final long identity = Binder.clearCallingIdentity();
2801 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002802 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002803 } finally {
2804 Binder.restoreCallingIdentity(identity);
2805 }
fionaxu235cc5e2017-03-06 22:25:57 -08002806 }
2807
Pengquan Meng0c05b502018-09-06 09:59:22 -07002808 @Override
2809 public int getNetworkSelectionMode(int subId) {
Pengquan Meng466e2482018-09-21 15:54:48 -07002810 if (!isActiveSubscription(subId)) {
2811 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2812 }
2813
Pengquan Meng0c05b502018-09-06 09:59:22 -07002814 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2815 }
2816
Brad Ebinger4c460712018-10-01 10:40:55 -07002817 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002818 public boolean isInEmergencySmsMode() {
2819 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2820 final long identity = Binder.clearCallingIdentity();
2821 try {
2822 for (Phone phone : PhoneFactory.getPhones()) {
2823 if (phone.isInEmergencySmsMode()) {
2824 return true;
2825 }
2826 }
2827 } finally {
2828 Binder.restoreCallingIdentity(identity);
2829 }
2830 return false;
2831 }
2832
2833 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002834 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2835 throws RemoteException {
2836 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002837 final long token = Binder.clearCallingIdentity();
2838 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002839 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002840 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002841 .addRegistrationCallbackForSubscription(c, subId);
2842 } finally {
2843 Binder.restoreCallingIdentity(token);
2844 }
2845 }
2846
2847 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002848 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2849 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002850 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2851 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2852 }
2853 Binder.withCleanCallingIdentity(() -> {
2854 try {
2855 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002856 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002857 .removeRegistrationCallbackForSubscription(c, subId);
2858 } catch (IllegalArgumentException e) {
2859 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2860 + "is inactive, ignoring unregister.");
2861 // If the subscription is no longer active, just return, since the callback
2862 // will already have been removed internally.
2863 }
2864 });
Brad Ebinger4c460712018-10-01 10:40:55 -07002865 }
2866
2867 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002868 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2869 throws RemoteException {
2870 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002871 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2872 final long token = Binder.clearCallingIdentity();
2873 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002874 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002875 .addCapabilitiesCallbackForSubscription(c, subId);
2876 } finally {
2877 Binder.restoreCallingIdentity(token);
2878 }
2879 }
2880
2881 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002882 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2883 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002884
2885 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2886 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2887 }
2888 Binder.withCleanCallingIdentity(() -> {
2889 try {
2890 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002891 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002892 .removeCapabilitiesCallbackForSubscription(c, subId);
2893 } catch (IllegalArgumentException e) {
2894 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
2895 + "is inactive, ignoring unregister.");
2896 // If the subscription is no longer active, just return, since the callback
2897 // will already have been removed internally.
2898 }
2899 });
Brad Ebinger4c460712018-10-01 10:40:55 -07002900 }
2901
2902 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002903 public boolean isCapable(int subId, int capability, int regTech) {
2904 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002905 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2906 final long token = Binder.clearCallingIdentity();
2907 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002908 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002909 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2910 } catch (ImsException e) {
2911 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2912 return false;
Brad Ebinger6b5ac222019-02-04 14:36:52 -08002913 } catch (IllegalArgumentException e) {
2914 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
2915 return false;
Brad Ebinger4c460712018-10-01 10:40:55 -07002916 } finally {
2917 Binder.restoreCallingIdentity(token);
2918 }
2919 }
2920
2921 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002922 public boolean isAvailable(int subId, int capability, int regTech) {
2923 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002924 final long token = Binder.clearCallingIdentity();
2925 try {
2926 Phone phone = getPhone(subId);
2927 if (phone == null) return false;
2928 return phone.isImsCapabilityAvailable(capability, regTech);
2929 } finally {
2930 Binder.restoreCallingIdentity(token);
2931 }
2932 }
2933
2934 @Override
2935 public boolean isAdvancedCallingSettingEnabled(int subId) {
2936 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2937 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2938 final long token = Binder.clearCallingIdentity();
2939 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002940 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002941 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2942 } finally {
2943 Binder.restoreCallingIdentity(token);
2944 }
2945 }
2946
2947 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08002948 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002949 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08002950 "setAdvancedCallingSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002951 final long identity = Binder.clearCallingIdentity();
2952 try {
2953 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002954 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002955 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2956 } finally {
2957 Binder.restoreCallingIdentity(identity);
2958 }
2959 }
2960
2961 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002962 public boolean isVtSettingEnabled(int subId) {
2963 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002964 final long identity = Binder.clearCallingIdentity();
2965 try {
2966 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002967 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002968 getSlotIndexOrException(subId)).isVtEnabledByUser();
2969 } finally {
2970 Binder.restoreCallingIdentity(identity);
2971 }
2972 }
2973
2974 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08002975 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002976 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08002977 "setVtSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002978 final long identity = Binder.clearCallingIdentity();
2979 try {
2980 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002981 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger4c460712018-10-01 10:40:55 -07002982 } finally {
2983 Binder.restoreCallingIdentity(identity);
2984 }
2985 }
2986
2987 @Override
2988 public boolean isVoWiFiSettingEnabled(int subId) {
2989 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
2990 final long identity = Binder.clearCallingIdentity();
2991 try {
2992 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002993 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002994 getSlotIndexOrException(subId)).isWfcEnabledByUser();
2995 } finally {
2996 Binder.restoreCallingIdentity(identity);
2997 }
2998 }
2999
3000 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08003001 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07003002 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08003003 "setVoWiFiSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07003004 final long identity = Binder.clearCallingIdentity();
3005 try {
3006 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003007 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger4c460712018-10-01 10:40:55 -07003008 } finally {
3009 Binder.restoreCallingIdentity(identity);
3010 }
3011 }
3012
3013 @Override
3014 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3015 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3016 final long identity = Binder.clearCallingIdentity();
3017 try {
3018 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003019 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003020 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
3021 } finally {
3022 Binder.restoreCallingIdentity(identity);
3023 }
3024 }
3025
3026 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08003027 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07003028 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08003029 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07003030 final long identity = Binder.clearCallingIdentity();
3031 try {
3032 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003033 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003034 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
3035 } finally {
3036 Binder.restoreCallingIdentity(identity);
3037 }
3038 }
3039
3040 @Override
3041 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3042 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3043 "setVoWiFiNonPersistent");
3044 final long identity = Binder.clearCallingIdentity();
3045 try {
3046 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003047 ImsManager.getInstance(mApp,
Brad Ebinger2bc95702019-05-07 18:33:46 -07003048 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger4c460712018-10-01 10:40:55 -07003049 } finally {
3050 Binder.restoreCallingIdentity(identity);
3051 }
3052 }
3053
3054 @Override
3055 public int getVoWiFiModeSetting(int subId) {
3056 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3057 final long identity = Binder.clearCallingIdentity();
3058 try {
3059 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003060 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003061 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
3062 } finally {
3063 Binder.restoreCallingIdentity(identity);
3064 }
3065 }
3066
3067 @Override
3068 public void setVoWiFiModeSetting(int subId, int mode) {
3069 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3070 "setVoWiFiModeSetting");
3071 final long identity = Binder.clearCallingIdentity();
3072 try {
3073 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003074 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003075 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
3076 } finally {
3077 Binder.restoreCallingIdentity(identity);
3078 }
3079 }
3080
3081 @Override
3082 public int getVoWiFiRoamingModeSetting(int subId) {
3083 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3084 final long identity = Binder.clearCallingIdentity();
3085 try {
3086 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003087 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003088 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
3089 } finally {
3090 Binder.restoreCallingIdentity(identity);
3091 }
3092 }
3093
3094 @Override
3095 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3096 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3097 "setVoWiFiRoamingModeSetting");
3098 final long identity = Binder.clearCallingIdentity();
3099 try {
3100 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003101 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003102 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
3103 } finally {
3104 Binder.restoreCallingIdentity(identity);
3105 }
3106 }
3107
3108 @Override
3109 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3110 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3111 "setRttCapabilityEnabled");
3112 final long identity = Binder.clearCallingIdentity();
3113 try {
3114 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003115 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003116 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3117 } finally {
3118 Binder.restoreCallingIdentity(identity);
3119 }
3120 }
3121
3122 @Override
3123 public boolean isTtyOverVolteEnabled(int subId) {
3124 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3125 final long identity = Binder.clearCallingIdentity();
3126 try {
3127 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003128 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003129 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
3130 } finally {
3131 Binder.restoreCallingIdentity(identity);
3132 }
3133 }
3134
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003135 @Override
3136 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3137 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3138 final long identity = Binder.clearCallingIdentity();
3139 try {
3140 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003141 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003142 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003143 } finally {
3144 Binder.restoreCallingIdentity(identity);
3145 }
3146 }
3147
3148 @Override
3149 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3150 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3151 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003152 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3153 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3154 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003155 try {
3156 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003157 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003158 .removeProvisioningCallbackForSubscription(callback, subId);
3159 } catch (IllegalArgumentException e) {
3160 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3161 + "is inactive, ignoring unregister.");
3162 // If the subscription is no longer active, just return, since the callback will already
3163 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003164 } finally {
3165 Binder.restoreCallingIdentity(identity);
3166 }
3167 }
3168
3169 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003170 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3171 boolean isProvisioned) {
3172 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3173 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3174 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3175 }
3176 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3177 "setProvisioningStatusForCapability");
3178 final long identity = Binder.clearCallingIdentity();
3179 try {
3180 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3181 Phone phone = getPhone(subId);
3182 if (phone == null) {
3183 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3184 + subId);
3185 return;
3186 }
3187 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3188 return;
3189 }
3190
3191 // this capability requires provisioning, route to the correct API.
3192 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3193 switch (capability) {
3194 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3195 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3196 ims.setVolteProvisioned(isProvisioned);
3197 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3198 ims.setWfcProvisioned(isProvisioned);
3199 }
3200 break;
3201 }
3202 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3203 // There is currently no difference in VT provisioning type.
3204 ims.setVtProvisioned(isProvisioned);
3205 break;
3206 }
3207 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3208 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3209 // change the capability of the feature instead if needed.
3210 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3211 == isProvisioned) {
3212 // No change in provisioning.
3213 return;
3214 }
3215 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3216 try {
3217 ims.changeMmTelCapability(capability, tech, isProvisioned);
3218 } catch (ImsException e) {
3219 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3220 + ", Exception" + e.getMessage());
3221 }
3222 break;
3223 }
3224 default: {
3225 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3226 + capability + "', which does not require provisioning.");
3227 }
3228 }
3229
3230 } finally {
3231 Binder.restoreCallingIdentity(identity);
3232 }
3233 }
3234
3235 @Override
3236 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3237 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3238 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3239 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3240 }
3241 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3242 final long identity = Binder.clearCallingIdentity();
3243 try {
3244 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3245 Phone phone = getPhone(subId);
3246 if (phone == null) {
3247 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3248 + subId);
3249 // We will fail with "true" as the provisioning status because this is the default
3250 // if we do not require provisioning.
3251 return true;
3252 }
3253
3254 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3255 return true;
3256 }
3257
3258 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3259 switch (capability) {
3260 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3261 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3262 return ims.isVolteProvisionedOnDevice();
3263 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3264 return ims.isWfcProvisionedOnDevice();
3265 }
3266 // This should never happen, since we are checking tech above to make sure it
3267 // is either LTE or IWLAN.
3268 throw new IllegalArgumentException("Invalid radio technology for voice "
3269 + "capability.");
3270 }
3271 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3272 // There is currently no difference in VT provisioning type.
3273 return ims.isVtProvisionedOnDevice();
3274 }
3275 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3276 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3277 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3278 }
3279 default: {
3280 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3281 + capability + "', which does not require provisioning.");
3282 }
3283 }
3284
3285 } finally {
3286 Binder.restoreCallingIdentity(identity);
3287 }
3288 }
3289
3290 @Override
3291 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3292 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3293 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3294 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3295 }
3296 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3297 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3298 return (provisionedBits & capability) > 0;
3299 }
3300
3301 @Override
3302 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3303 boolean isProvisioned) {
3304 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3305 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3306 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3307 }
3308 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3309 "setProvisioningStatusForCapability");
3310 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3311 // If the current provisioning status for capability already matches isProvisioned,
3312 // do nothing.
3313 if (((provisionedBits & capability) > 0) == isProvisioned) {
3314 return;
3315 }
3316 if (isProvisioned) {
3317 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3318 } else {
3319 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3320 }
3321 }
3322
3323 /**
3324 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3325 * technology. The bitfield should mirror the bitfield defined by
3326 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3327 */
3328 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3329 String key = getMmTelProvisioningKey(subId, tech);
3330 // Default is no capabilities are provisioned.
3331 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3332 }
3333
3334 /**
3335 * Sets the MmTel capability provisioning bitfield (defined by
3336 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3337 * technology specified.
3338 *
3339 * Note: This is a synchronous command and should not be called on UI thread.
3340 */
3341 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3342 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3343 String key = getMmTelProvisioningKey(subId, tech);
3344 editor.putInt(key, newField);
3345 editor.commit();
3346 }
3347
3348 private static String getMmTelProvisioningKey(int subId, int tech) {
3349 // resulting key is provision_ims_mmtel_{subId}_{tech}
3350 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3351 }
3352
3353 /**
3354 * Query CarrierConfig to see if the specified capability requires provisioning for the
3355 * carrier associated with the subscription id.
3356 */
3357 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3358 int capability) {
3359 CarrierConfigManager configManager = new CarrierConfigManager(context);
3360 PersistableBundle c = configManager.getConfigForSubId(subId);
3361 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07003362 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003363 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3364 false);
3365 boolean requireVoiceVtProvisioning = c.getBoolean(
3366 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3367
3368 // First check to make sure that the capability requires provisioning.
3369 switch (capability) {
3370 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3371 // intentional fallthrough
3372 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3373 if (requireVoiceVtProvisioning) {
3374 // Voice and Video requires provisioning
3375 return true;
3376 }
3377 break;
3378 }
3379 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3380 if (requireUtProvisioning) {
3381 // UT requires provisioning
3382 return true;
3383 }
3384 break;
3385 }
3386 }
3387 return false;
3388 }
3389
3390 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003391 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003392 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3393 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3394 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003395 enforceReadPrivilegedPermission("getImsProvisioningInt");
3396 final long identity = Binder.clearCallingIdentity();
3397 try {
3398 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003399 int slotId = getSlotIndex(subId);
3400 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3401 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3402 + subId + "' for key:" + key);
3403 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3404 }
3405 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003406 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003407 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3408 + subId + "' for key:" + key);
3409 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003410 } finally {
3411 Binder.restoreCallingIdentity(identity);
3412 }
3413 }
3414
3415 @Override
3416 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003417 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3418 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3419 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003420 enforceReadPrivilegedPermission("getImsProvisioningString");
3421 final long identity = Binder.clearCallingIdentity();
3422 try {
3423 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003424 int slotId = getSlotIndex(subId);
3425 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3426 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3427 + subId + "' for key:" + key);
3428 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3429 }
3430 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003431 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003432 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3433 + subId + "' for key:" + key);
3434 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003435 } finally {
3436 Binder.restoreCallingIdentity(identity);
3437 }
3438 }
3439
3440 @Override
3441 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003442 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3443 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3444 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003445 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3446 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003447 final long identity = Binder.clearCallingIdentity();
3448 try {
3449 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003450 int slotId = getSlotIndex(subId);
3451 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3452 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3453 + subId + "' for key:" + key);
3454 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3455 }
3456 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003457 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003458 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3459 + "' for key:" + key);
3460 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003461 } finally {
3462 Binder.restoreCallingIdentity(identity);
3463 }
3464 }
3465
3466 @Override
3467 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003468 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3469 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3470 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003471 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3472 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003473 final long identity = Binder.clearCallingIdentity();
3474 try {
3475 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003476 int slotId = getSlotIndex(subId);
3477 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3478 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3479 + subId + "' for key:" + key);
3480 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3481 }
3482 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003483 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003484 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3485 + "' for key:" + key);
3486 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003487 } finally {
3488 Binder.restoreCallingIdentity(identity);
3489 }
3490 }
3491
Brad Ebinger4c460712018-10-01 10:40:55 -07003492 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
3493 int slotId = SubscriptionManager.getSlotIndex(subId);
3494 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003495 throw new IllegalArgumentException("Invalid Subscription Id, subId=" + subId);
Brad Ebinger4c460712018-10-01 10:40:55 -07003496 }
3497 return slotId;
3498 }
3499
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003500 private int getSlotIndex(int subId) {
3501 int slotId = SubscriptionManager.getSlotIndex(subId);
3502 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3503 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3504 }
3505 return slotId;
3506 }
3507
Wink Saville36469e72014-06-11 15:17:00 -07003508 /**
Nathan Haroldb3a3a802019-05-21 15:51:27 -07003509 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07003510 */
3511 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003512 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07003513 final int targetSdk = getTargetSdk(callingPackage);
3514 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
3515 return getDataNetworkTypeForSubscriber(subId, callingPackage);
3516 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Haroldb3a3a802019-05-21 15:51:27 -07003517 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
3518 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003519 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3520 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003521
Malcolm Chend965c8b2018-02-28 15:00:40 -08003522 final long identity = Binder.clearCallingIdentity();
3523 try {
3524 final Phone phone = getPhone(subId);
3525 if (phone != null) {
3526 return phone.getServiceState().getDataNetworkType();
3527 } else {
3528 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3529 }
3530 } finally {
3531 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003532 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003533 }
3534
3535 /**
3536 * Returns the data network type
3537 */
3538 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003539 public int getDataNetworkType(String callingPackage) {
3540 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003541 }
3542
3543 /**
3544 * Returns the data network type for a subId
3545 */
3546 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003547 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003548 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003549 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003550 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3551 }
3552
Malcolm Chend965c8b2018-02-28 15:00:40 -08003553 final long identity = Binder.clearCallingIdentity();
3554 try {
3555 final Phone phone = getPhone(subId);
3556 if (phone != null) {
3557 return phone.getServiceState().getDataNetworkType();
3558 } else {
3559 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3560 }
3561 } finally {
3562 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003563 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003564 }
3565
3566 /**
Wink Saville36469e72014-06-11 15:17:00 -07003567 * Returns the Voice network type for a subId
3568 */
3569 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003570 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003571 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003572 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003573 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3574 }
3575
Malcolm Chend965c8b2018-02-28 15:00:40 -08003576 final long identity = Binder.clearCallingIdentity();
3577 try {
3578 final Phone phone = getPhone(subId);
3579 if (phone != null) {
3580 return phone.getServiceState().getVoiceNetworkType();
3581 } else {
3582 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3583 }
3584 } finally {
3585 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003586 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003587 }
3588
3589 /**
3590 * @return true if a ICC card is present
3591 */
3592 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003593 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003594 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3595 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003596 }
3597
3598 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003599 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003600 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003601 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003602 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003603 final long identity = Binder.clearCallingIdentity();
3604 try {
3605 final Phone phone = PhoneFactory.getPhone(slotIndex);
3606 if (phone != null) {
3607 return phone.getIccCard().hasIccCard();
3608 } else {
3609 return false;
3610 }
3611 } finally {
3612 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003613 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003614 }
3615
3616 /**
3617 * Return if the current radio is LTE on CDMA. This
3618 * is a tri-state return value as for a period of time
3619 * the mode may be unknown.
3620 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003621 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003622 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003623 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003624 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003625 @Override
3626 public int getLteOnCdmaMode(String callingPackage) {
3627 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003628 }
3629
Sanket Padawe356d7632015-06-22 14:03:32 -07003630 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003631 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003632 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003633 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003634 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3635 }
3636
Malcolm Chend965c8b2018-02-28 15:00:40 -08003637 final long identity = Binder.clearCallingIdentity();
3638 try {
3639 final Phone phone = getPhone(subId);
3640 if (phone == null) {
3641 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3642 } else {
3643 return phone.getLteOnCdmaMode();
3644 }
3645 } finally {
3646 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003647 }
Wink Saville36469e72014-06-11 15:17:00 -07003648 }
3649
Wink Saville36469e72014-06-11 15:17:00 -07003650 /**
3651 * {@hide}
3652 * Returns Default subId, 0 in the case of single standby.
3653 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003654 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003655 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003656 }
3657
Shishir Agrawala9f32182016-04-12 12:00:16 -07003658 private int getSlotForDefaultSubscription() {
3659 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3660 }
3661
Wink Savilleb564aae2014-10-23 10:18:09 -07003662 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003663 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003664 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003665
Pengquan Meng466e2482018-09-21 15:54:48 -07003666 private boolean isActiveSubscription(int subId) {
3667 return mSubscriptionController.isActiveSubId(subId);
3668 }
3669
Ihab Awadf2177b72013-11-25 13:33:23 -08003670 /**
3671 * @see android.telephony.TelephonyManager.WifiCallingChoices
3672 */
3673 public int getWhenToMakeWifiCalls() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003674 final long identity = Binder.clearCallingIdentity();
3675 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003676 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003677 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3678 getWhenToMakeWifiCallsDefaultPreference());
3679 } finally {
3680 Binder.restoreCallingIdentity(identity);
3681 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003682 }
3683
3684 /**
3685 * @see android.telephony.TelephonyManager.WifiCallingChoices
3686 */
3687 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003688 final long identity = Binder.clearCallingIdentity();
3689 try {
3690 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003691 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003692 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3693 } finally {
3694 Binder.restoreCallingIdentity(identity);
3695 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003696 }
3697
Sailesh Nepald1e68152013-12-12 19:08:02 -08003698 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003699 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003700 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003701 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003702
Jordan Liu73b078d2019-02-28 12:03:40 -08003703 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
3704 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
3705 if (phoneId == -1) {
3706 throw new IllegalArgumentException("Given slot index: " + slotIndex
3707 + " does not correspond to an active phone");
3708 }
3709 return PhoneFactory.getPhone(phoneId);
3710 }
3711
Shishir Agrawal566b7612013-10-28 14:41:00 -07003712 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003713 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3714 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003715 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3716 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003717 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu73b078d2019-02-28 12:03:40 -08003718 if (DBG) {
3719 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3720 }
3721 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
3722 p2);
3723 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003724
Jordan Liu73b078d2019-02-28 12:03:40 -08003725
3726 @Override
3727 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
3728 int slotIndex, String callingPackage, String aid, int p2) {
3729 enforceModifyPermission();
3730 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3731 if (DBG) {
3732 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
3733 }
3734 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3735 callingPackage, aid, p2);
3736 }
3737
3738 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
3739 String callingPackage, String aid, int p2) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003740 final long identity = Binder.clearCallingIdentity();
3741 try {
3742 if (TextUtils.equals(ISDR_AID, aid)) {
3743 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003744 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3745 .getContext().getPackageManager());
Malcolm Chend965c8b2018-02-28 15:00:40 -08003746 if (bestComponent == null
3747 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3748 loge("The calling package is not allowed to access ISD-R.");
3749 throw new SecurityException(
3750 "The calling package is not allowed to access ISD-R.");
3751 }
Derek Tan740e1672017-06-27 14:56:27 -07003752 }
Derek Tan740e1672017-06-27 14:56:27 -07003753
Malcolm Chend965c8b2018-02-28 15:00:40 -08003754 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu73b078d2019-02-28 12:03:40 -08003755 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
3756 null /* workSource */);
3757 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003758 return response;
3759 } finally {
3760 Binder.restoreCallingIdentity(identity);
3761 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003762 }
3763
3764 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003765 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003766 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3767 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu73b078d2019-02-28 12:03:40 -08003768 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3769 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
3770 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003771
Jordan Liu73b078d2019-02-28 12:03:40 -08003772 @Override
3773 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
3774 enforceModifyPermission();
3775 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
3776 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3777 channel);
3778 }
3779
3780 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003781 final long identity = Binder.clearCallingIdentity();
3782 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003783 if (channel < 0) {
3784 return false;
3785 }
Jordan Liu73b078d2019-02-28 12:03:40 -08003786 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
3787 null /* workSource */);
3788 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003789 return success;
3790 } finally {
3791 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003792 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003793 }
3794
3795 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003796 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003797 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003798 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3799 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu73b078d2019-02-28 12:03:40 -08003800 if (DBG) {
3801 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3802 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3803 + p3 + " data=" + data);
3804 }
3805 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
3806 command, p1, p2, p3, data);
3807 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003808
Jordan Liu73b078d2019-02-28 12:03:40 -08003809 @Override
3810 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
3811 int command, int p1, int p2, int p3, String data) {
3812 enforceModifyPermission();
3813 if (DBG) {
3814 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
3815 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3816 + p3 + " data=" + data);
3817 }
3818 return iccTransmitApduLogicalChannelWithPermission(
3819 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
3820 data);
3821 }
3822
3823 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
3824 int command, int p1, int p2, int p3, String data) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003825 final long identity = Binder.clearCallingIdentity();
3826 try {
Hall Liucdcfa292019-05-02 09:16:29 -07003827 if (channel <= 0) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003828 return "";
3829 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003830
Malcolm Chend965c8b2018-02-28 15:00:40 -08003831 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu73b078d2019-02-28 12:03:40 -08003832 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
3833 null /* workSource */);
3834 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003835
Malcolm Chend965c8b2018-02-28 15:00:40 -08003836 // Append the returned status code to the end of the response payload.
3837 String s = Integer.toHexString(
3838 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3839 if (response.payload != null) {
3840 s = IccUtils.bytesToHexString(response.payload) + s;
3841 }
3842 return s;
3843 } finally {
3844 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003845 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003846 }
Jake Hambye994d462014-02-03 13:10:13 -08003847
Evan Charltonc66da362014-05-16 14:06:40 -07003848 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003849 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3850 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003851 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3852 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003853 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu73b078d2019-02-28 12:03:40 -08003854 if (DBG) {
3855 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3856 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3857 }
3858 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
3859 cla, command, p1, p2, p3, data);
3860 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003861
Jordan Liu73b078d2019-02-28 12:03:40 -08003862 @Override
3863 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
3864 int command, int p1, int p2, int p3, String data) {
3865 enforceModifyPermission();
3866 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3867 if (DBG) {
3868 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
3869 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
3870 + " data=" + data);
3871 }
3872
3873 return iccTransmitApduBasicChannelWithPermission(
3874 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
3875 p2, p3, data);
3876 }
3877
3878 // open APDU basic channel assuming the caller has sufficient permissions
3879 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
3880 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003881 final long identity = Binder.clearCallingIdentity();
3882 try {
3883 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3884 && TextUtils.equals(ISDR_AID, data)) {
3885 // Only allows LPA to select ISD-R.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003886 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3887 .getContext().getPackageManager());
Malcolm Chend965c8b2018-02-28 15:00:40 -08003888 if (bestComponent == null
3889 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3890 loge("The calling package is not allowed to select ISD-R.");
3891 throw new SecurityException(
3892 "The calling package is not allowed to select ISD-R.");
3893 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003894 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003895
Malcolm Chend965c8b2018-02-28 15:00:40 -08003896 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu73b078d2019-02-28 12:03:40 -08003897 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
3898 null /* workSource */);
3899 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003900
Malcolm Chend965c8b2018-02-28 15:00:40 -08003901 // Append the returned status code to the end of the response payload.
3902 String s = Integer.toHexString(
3903 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3904 if (response.payload != null) {
3905 s = IccUtils.bytesToHexString(response.payload) + s;
3906 }
3907 return s;
3908 } finally {
3909 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003910 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003911 }
3912
3913 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003914 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003915 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003916 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3917 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003918
Malcolm Chend965c8b2018-02-28 15:00:40 -08003919 final long identity = Binder.clearCallingIdentity();
3920 try {
3921 if (DBG) {
3922 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3923 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3924 }
3925
3926 IccIoResult response =
3927 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3928 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3929 subId);
3930
3931 if (DBG) {
3932 log("Exchange SIM_IO [R]" + response);
3933 }
3934
3935 byte[] result = null;
3936 int length = 2;
3937 if (response.payload != null) {
3938 length = 2 + response.payload.length;
3939 result = new byte[length];
3940 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3941 } else {
3942 result = new byte[length];
3943 }
3944
3945 result[length - 1] = (byte) response.sw2;
3946 result[length - 2] = (byte) response.sw1;
3947 return result;
3948 } finally {
3949 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003950 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003951 }
3952
Nathan Haroldb3014052017-01-25 15:57:32 -08003953 /**
3954 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3955 * on a particular subscription
3956 */
sqianb6e41952018-03-12 14:54:01 -07003957 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3958 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3959 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3960 return null;
3961 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003962
3963 final long identity = Binder.clearCallingIdentity();
3964 try {
3965 if (appType != TelephonyManager.APPTYPE_USIM
3966 && appType != TelephonyManager.APPTYPE_SIM) {
3967 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3968 return null;
3969 }
3970 Object response = sendRequest(
3971 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3972 if (response instanceof String[]) {
3973 return (String[]) response;
3974 }
3975 // Response is an Exception of some kind,
3976 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003977 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08003978 } finally {
3979 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003980 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003981 }
3982
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003983 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003984 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003985 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3986 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003987
Malcolm Chend965c8b2018-02-28 15:00:40 -08003988 final long identity = Binder.clearCallingIdentity();
3989 try {
3990 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3991 if (response.payload == null) {
3992 return "";
3993 }
Evan Charltonc66da362014-05-16 14:06:40 -07003994
Malcolm Chend965c8b2018-02-28 15:00:40 -08003995 // Append the returned status code to the end of the response payload.
3996 String s = Integer.toHexString(
3997 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3998 s = IccUtils.bytesToHexString(response.payload) + s;
3999 return s;
4000 } finally {
4001 Binder.restoreCallingIdentity(identity);
4002 }
Evan Charltonc66da362014-05-16 14:06:40 -07004003 }
4004
Jake Hambye994d462014-02-03 13:10:13 -08004005 /**
4006 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4007 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4008 *
4009 * @param itemID the ID of the item to read
4010 * @return the NV item as a String, or null on error.
4011 */
4012 @Override
4013 public String nvReadItem(int itemID) {
vagdevie435a3e2018-08-15 16:01:53 -07004014 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004015 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4016 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004017
4018 final long identity = Binder.clearCallingIdentity();
4019 try {
4020 if (DBG) log("nvReadItem: item " + itemID);
vagdevie435a3e2018-08-15 16:01:53 -07004021 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004022 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4023 return value;
4024 } finally {
4025 Binder.restoreCallingIdentity(identity);
4026 }
Jake Hambye994d462014-02-03 13:10:13 -08004027 }
4028
4029 /**
4030 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4031 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4032 *
4033 * @param itemID the ID of the item to read
4034 * @param itemValue the value to write, as a String
4035 * @return true on success; false on any failure
4036 */
4037 @Override
4038 public boolean nvWriteItem(int itemID, String itemValue) {
vagdevie435a3e2018-08-15 16:01:53 -07004039 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004040 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4041 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004042
4043 final long identity = Binder.clearCallingIdentity();
4044 try {
4045 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4046 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdevie435a3e2018-08-15 16:01:53 -07004047 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004048 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4049 return success;
4050 } finally {
4051 Binder.restoreCallingIdentity(identity);
4052 }
Jake Hambye994d462014-02-03 13:10:13 -08004053 }
4054
4055 /**
4056 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4057 * Used for device configuration by some CDMA operators.
4058 *
4059 * @param preferredRoamingList byte array containing the new PRL
4060 * @return true on success; false on any failure
4061 */
4062 @Override
4063 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004064 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4065 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004066
4067 final long identity = Binder.clearCallingIdentity();
4068 try {
4069 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4070 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4071 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4072 return success;
4073 } finally {
4074 Binder.restoreCallingIdentity(identity);
4075 }
Jake Hambye994d462014-02-03 13:10:13 -08004076 }
4077
4078 /**
chen xu1cc0abe2018-10-26 17:39:23 -07004079 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004080 * Used for device configuration by some CDMA operators.
4081 *
chen xu1cc0abe2018-10-26 17:39:23 -07004082 * @param slotIndex - device slot.
4083 *
Jake Hambye994d462014-02-03 13:10:13 -08004084 * @return true on success; false on any failure
4085 */
4086 @Override
chen xu1cc0abe2018-10-26 17:39:23 -07004087 public boolean resetModemConfig(int slotIndex) {
4088 Phone phone = PhoneFactory.getPhone(slotIndex);
4089 if (phone != null) {
4090 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4091 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004092
chen xu1cc0abe2018-10-26 17:39:23 -07004093 final long identity = Binder.clearCallingIdentity();
4094 try {
4095 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4096 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4097 return success;
4098 } finally {
4099 Binder.restoreCallingIdentity(identity);
4100 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004101 }
chen xu1cc0abe2018-10-26 17:39:23 -07004102 return false;
4103 }
4104
4105 /**
4106 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4107 *
4108 * @param slotIndex - device slot.
4109 *
4110 * @return true on success; false on any failure
4111 */
4112 @Override
4113 public boolean rebootModem(int slotIndex) {
4114 Phone phone = PhoneFactory.getPhone(slotIndex);
4115 if (phone != null) {
4116 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4117 mApp, phone.getSubId(), "rebootModem");
4118
4119 final long identity = Binder.clearCallingIdentity();
4120 try {
4121 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4122 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4123 return success;
4124 } finally {
4125 Binder.restoreCallingIdentity(identity);
4126 }
4127 }
4128 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004129 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004130
Svet Ganovb320e182015-04-16 12:30:10 -07004131 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004132 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004133 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004134 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004135 return new String[0];
4136 }
4137
Malcolm Chend965c8b2018-02-28 15:00:40 -08004138 final long identity = Binder.clearCallingIdentity();
4139 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004140 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004141 } finally {
4142 Binder.restoreCallingIdentity(identity);
4143 }
Wink Saville36469e72014-06-11 15:17:00 -07004144 }
4145
Brad Ebinger51f743a2017-01-23 13:50:20 -08004146 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004147 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4148 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004149 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004150 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004151 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004152
4153 final long identity = Binder.clearCallingIdentity();
4154 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004155 ImsResolver resolver = PhoneFactory.getImsResolver();
4156 if (resolver == null) {
4157 // may happen if the device does not support IMS.
4158 return;
4159 }
4160 resolver.enableIms(slotId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004161 } finally {
4162 Binder.restoreCallingIdentity(identity);
4163 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004164 }
4165
4166 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004167 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4168 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004169 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004170 public void disableIms(int slotId) {
4171 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004172
4173 final long identity = Binder.clearCallingIdentity();
4174 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004175 ImsResolver resolver = PhoneFactory.getImsResolver();
4176 if (resolver == null) {
4177 // may happen if the device does not support IMS.
4178 return;
4179 }
4180 resolver.disableIms(slotId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004181 } finally {
4182 Binder.restoreCallingIdentity(identity);
4183 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004184 }
4185
4186 /**
4187 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4188 * feature or {@link null} if the service is not available. If the feature is available, the
4189 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4190 */
4191 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004192 IImsServiceFeatureCallback callback) {
4193 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004194
4195 final long identity = Binder.clearCallingIdentity();
4196 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004197 ImsResolver resolver = PhoneFactory.getImsResolver();
4198 if (resolver == null) {
4199 // may happen if the device does not support IMS.
4200 return null;
4201 }
4202 return resolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004203 } finally {
4204 Binder.restoreCallingIdentity(identity);
4205 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004206 }
4207
4208 /**
4209 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4210 * feature during emergency calling or {@link null} if the service is not available. If the
4211 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4212 * listener for feature updates.
4213 */
4214 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4215 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004216
4217 final long identity = Binder.clearCallingIdentity();
4218 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004219 ImsResolver resolver = PhoneFactory.getImsResolver();
4220 if (resolver == null) {
4221 // may happen if the device does not support IMS.
4222 return null;
4223 }
4224 return resolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004225 } finally {
4226 Binder.restoreCallingIdentity(identity);
4227 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004228 }
4229
Brad Ebinger5f64b052017-12-14 14:26:15 -08004230 /**
4231 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebingereb160e22019-01-23 15:06:19 -08004232 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004233 */
4234 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4235 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004236
4237 final long identity = Binder.clearCallingIdentity();
4238 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004239 ImsResolver resolver = PhoneFactory.getImsResolver();
4240 if (resolver == null) {
4241 // may happen if the device does not support IMS.
4242 return null;
4243 }
4244 return resolver.getImsRegistration(slotId, feature);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004245 } finally {
4246 Binder.restoreCallingIdentity(identity);
4247 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004248 }
4249
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004250 /**
4251 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebingereb160e22019-01-23 15:06:19 -08004252 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004253 */
4254 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4255 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004256
4257 final long identity = Binder.clearCallingIdentity();
4258 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004259 ImsResolver resolver = PhoneFactory.getImsResolver();
4260 if (resolver == null) {
4261 // may happen if the device does not support IMS.
4262 return null;
4263 }
4264 return resolver.getImsConfig(slotId, feature);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004265 } finally {
4266 Binder.restoreCallingIdentity(identity);
4267 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004268 }
4269
Brad Ebinger884c07b2018-02-15 16:17:40 -08004270 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004271 * Sets the ImsService Package Name that Telephony will bind to.
4272 *
4273 * @param slotId the slot ID that the ImsService should bind for.
4274 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4275 * ImsService is the device default ImsService.
4276 * @param packageName The package name of the application that contains the ImsService to bind
4277 * to.
4278 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4279 * @hide
4280 */
4281 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004282 int[] subIds = SubscriptionManager.getSubId(slotId);
4283 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4284 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4285 "setImsService");
4286
Malcolm Chend965c8b2018-02-28 15:00:40 -08004287 final long identity = Binder.clearCallingIdentity();
4288 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004289 ImsResolver resolver = PhoneFactory.getImsResolver();
4290 if (resolver == null) {
4291 // may happen if the device does not support IMS.
4292 return false;
4293 }
4294 return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService,
4295 packageName);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004296 } finally {
4297 Binder.restoreCallingIdentity(identity);
4298 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004299 }
4300
4301 /**
4302 * Return the ImsService configuration.
4303 *
4304 * @param slotId The slot that the ImsService is associated with.
4305 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4306 * the device default.
4307 * @return the package name of the ImsService configuration.
4308 */
4309 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004310 int[] subIds = SubscriptionManager.getSubId(slotId);
4311 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4312 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4313 "getImsService");
4314
Malcolm Chend965c8b2018-02-28 15:00:40 -08004315 final long identity = Binder.clearCallingIdentity();
4316 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004317 ImsResolver resolver = PhoneFactory.getImsResolver();
4318 if (resolver == null) {
4319 // may happen if the device does not support IMS.
4320 return "";
4321 }
4322 return resolver.getImsServiceConfiguration(slotId, isCarrierImsService);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004323 } finally {
4324 Binder.restoreCallingIdentity(identity);
4325 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004326 }
4327
Wink Saville36469e72014-06-11 15:17:00 -07004328 public void setImsRegistrationState(boolean registered) {
4329 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004330
4331 final long identity = Binder.clearCallingIdentity();
4332 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004333 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004334 } finally {
4335 Binder.restoreCallingIdentity(identity);
4336 }
Wink Saville36469e72014-06-11 15:17:00 -07004337 }
4338
4339 /**
Stuart Scott54788802015-03-30 13:18:01 -07004340 * Set the network selection mode to automatic.
4341 *
4342 */
4343 @Override
4344 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004345 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4346 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004347
Pengquan Meng466e2482018-09-21 15:54:48 -07004348 if (!isActiveSubscription(subId)) {
4349 return;
4350 }
4351
Malcolm Chend965c8b2018-02-28 15:00:40 -08004352 final long identity = Binder.clearCallingIdentity();
4353 try {
4354 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4355 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4356 } finally {
4357 Binder.restoreCallingIdentity(identity);
4358 }
Stuart Scott54788802015-03-30 13:18:01 -07004359 }
4360
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004361 /**
4362 * Ask the radio to connect to the input network and change selection mode to manual.
4363 *
4364 * @param subId the id of the subscription.
4365 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4366 * the operator to attach to.
4367 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4368 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4369 * normal network selection next time.
4370 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004371 */
4372 @Override
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004373 public boolean setNetworkSelectionModeManual(
4374 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004375 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4376 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Meng466e2482018-09-21 15:54:48 -07004377
4378 if (!isActiveSubscription(subId)) {
4379 return false;
4380 }
4381
Malcolm Chend965c8b2018-02-28 15:00:40 -08004382 final long identity = Binder.clearCallingIdentity();
4383 try {
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004384 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chend965c8b2018-02-28 15:00:40 -08004385 persistSelection);
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004386 if (DBG) {
4387 log("setNetworkSelectionModeManual: subId: " + subId
4388 + " operator: " + operatorInfo);
4389 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004390 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4391 } finally {
4392 Binder.restoreCallingIdentity(identity);
4393 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004394 }
4395
4396 /**
4397 * Scans for available networks.
4398 */
4399 @Override
Hall Liuf19c44f2018-11-27 14:38:17 -08004400 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004401 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4402 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004403 LocationAccessPolicy.LocationPermissionResult locationResult =
4404 LocationAccessPolicy.checkLocationPermission(mApp,
4405 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4406 .setCallingPackage(callingPackage)
4407 .setCallingPid(Binder.getCallingPid())
4408 .setCallingUid(Binder.getCallingUid())
4409 .setMethod("getCellNetworkScanResults")
4410 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4411 .build());
4412 switch (locationResult) {
4413 case DENIED_HARD:
4414 throw new SecurityException("Not allowed to access scan results -- location");
4415 case DENIED_SOFT:
4416 return null;
4417 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004418
Pengquan Meng0c05b502018-09-06 09:59:22 -07004419 long identity = Binder.clearCallingIdentity();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004420 try {
4421 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Meng0c05b502018-09-06 09:59:22 -07004422 return (CellNetworkScanResult) sendRequest(
Malcolm Chend965c8b2018-02-28 15:00:40 -08004423 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004424 } finally {
4425 Binder.restoreCallingIdentity(identity);
4426 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004427 }
4428
4429 /**
yinxub1bed742017-04-17 11:45:04 -07004430 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004431 *
yinxub1bed742017-04-17 11:45:04 -07004432 * @param subId id of the subscription
4433 * @param request contains the radio access networks with bands/channels to scan
4434 * @param messenger callback messenger for scan results or errors
4435 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004436 * @return the id of the requested scan which can be used to stop the scan.
4437 */
4438 @Override
4439 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Hall Liuf19c44f2018-11-27 14:38:17 -08004440 IBinder binder, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004441 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4442 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004443 LocationAccessPolicy.LocationPermissionResult locationResult =
4444 LocationAccessPolicy.checkLocationPermission(mApp,
4445 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4446 .setCallingPackage(callingPackage)
4447 .setCallingPid(Binder.getCallingPid())
4448 .setCallingUid(Binder.getCallingUid())
4449 .setMethod("requestNetworkScan")
4450 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4451 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004452 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
4453 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request);
4454 if (e != null) {
4455 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4456 throw e;
4457 } else {
Hall Liu46dd96a2019-04-03 12:50:44 -07004458 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004459 return TelephonyScanManager.INVALID_SCAN_ID;
4460 }
4461 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004462 }
Hall Liubac7d482019-04-25 14:02:26 -07004463 int callingUid = Binder.getCallingUid();
4464 int callingPid = Binder.getCallingPid();
yinxu612a8192019-04-18 10:38:27 -07004465 final long identity = Binder.clearCallingIdentity();
4466 try {
4467 return mNetworkScanRequestTracker.startNetworkScan(
4468 request, messenger, binder, getPhone(subId),
Hall Liubac7d482019-04-25 14:02:26 -07004469 callingUid, callingPid, callingPackage);
yinxu612a8192019-04-18 10:38:27 -07004470 } finally {
4471 Binder.restoreCallingIdentity(identity);
4472 }
yinxu504e1392017-04-12 16:03:22 -07004473 }
4474
Hall Liub2ac8ef2019-02-28 15:56:23 -08004475 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
4476 NetworkScanRequest request) {
4477 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4478 != PERMISSION_GRANTED) {
4479 return new SecurityException("permission.NETWORK_SCAN is needed for network scans"
4480 + " without location access.");
4481 }
4482
4483 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4484 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004485 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4486 return new SecurityException("Specific channels must not be"
4487 + " scanned without location access.");
4488 }
4489 }
4490 }
4491
Hall Liub2ac8ef2019-02-28 15:56:23 -08004492 return null;
4493 }
4494
yinxu504e1392017-04-12 16:03:22 -07004495 /**
4496 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004497 *
4498 * @param subId id of the subscription
4499 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004500 */
4501 @Override
4502 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004503 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4504 mApp, subId, "stopNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004505
Hall Liubac7d482019-04-25 14:02:26 -07004506 int callingUid = Binder.getCallingUid();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004507 final long identity = Binder.clearCallingIdentity();
4508 try {
Hall Liubac7d482019-04-25 14:02:26 -07004509 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004510 } finally {
4511 Binder.restoreCallingIdentity(identity);
4512 }
yinxu504e1392017-04-12 16:03:22 -07004513 }
4514
4515 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004516 * Get the calculated preferred network type.
4517 * Used for debugging incorrect network type.
4518 *
4519 * @return the preferred network type, defined in RILConstants.java.
4520 */
4521 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004522 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004523 final Phone defaultPhone = getDefaultPhone();
4524 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4525 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004526 return RILConstants.PREFERRED_NETWORK_MODE;
4527 }
4528
Malcolm Chend965c8b2018-02-28 15:00:40 -08004529 final long identity = Binder.clearCallingIdentity();
4530 try {
4531 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004532 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004533 } finally {
4534 Binder.restoreCallingIdentity(identity);
4535 }
Junda Liu84d15a22014-07-02 11:21:04 -07004536 }
4537
4538 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004539 * Get the preferred network type.
4540 * Used for device configuration by some CDMA operators.
4541 *
4542 * @return the preferred network type, defined in RILConstants.java.
4543 */
4544 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004545 public int getPreferredNetworkType(int subId) {
Pengquan Meng4848cd02018-12-20 11:00:24 -08004546 TelephonyPermissions
4547 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4548 mApp, subId, "getPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004549
4550 final long identity = Binder.clearCallingIdentity();
4551 try {
4552 if (DBG) log("getPreferredNetworkType");
4553 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4554 int networkType = (result != null ? result[0] : -1);
4555 if (DBG) log("getPreferredNetworkType: " + networkType);
4556 return networkType;
4557 } finally {
4558 Binder.restoreCallingIdentity(identity);
4559 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004560 }
4561
4562 /**
4563 * Set the preferred network type.
4564 * Used for device configuration by some CDMA operators.
4565 *
4566 * @param networkType the preferred network type, defined in RILConstants.java.
4567 * @return true on success; false on any failure.
4568 */
4569 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004570 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004571 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4572 mApp, subId, "setPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004573
4574 final long identity = Binder.clearCallingIdentity();
4575 try {
4576 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4577 Boolean success = (Boolean) sendRequest(
4578 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4579 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4580 if (success) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004581 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08004582 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4583 }
4584 return success;
4585 } finally {
4586 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004587 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004588 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004589
4590 /**
Miaoa84611c2019-03-15 09:21:10 +08004591 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004592 *
Miaoa84611c2019-03-15 09:21:10 +08004593 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004594 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004595 * @hide
4596 */
4597 @Override
Miaoa84611c2019-03-15 09:21:10 +08004598 public boolean getTetherApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004599 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004600 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08004601 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004602 try {
Miaoa84611c2019-03-15 09:21:10 +08004603 if (phone != null) {
4604 return phone.hasMatchedTetherApnSetting();
4605 } else {
4606 return false;
4607 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004608 } finally {
4609 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004610 }
Junda Liu475951f2014-11-07 16:45:03 -08004611 }
4612
4613 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004614 * Set mobile data enabled
4615 * Used by the user through settings etc to turn on/off mobile data
4616 *
4617 * @param enable {@code true} turn turn data on, else {@code false}
4618 */
4619 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004620 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004621 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4622 mApp, subId, "setUserDataEnabled");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004623
4624 final long identity = Binder.clearCallingIdentity();
4625 try {
4626 int phoneId = mSubscriptionController.getPhoneId(subId);
4627 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4628 Phone phone = PhoneFactory.getPhone(phoneId);
4629 if (phone != null) {
4630 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yu7a030e52018-12-13 11:51:28 -08004631 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004632 } else {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004633 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004634 }
4635 } finally {
4636 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004637 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004638 }
4639
4640 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004641 * Get the user enabled state of Mobile Data.
4642 *
4643 * TODO: remove and use isUserDataEnabled.
4644 * This can't be removed now because some vendor codes
4645 * calls through ITelephony directly while they should
4646 * use TelephonyManager.
4647 *
4648 * @return true on enabled
4649 */
4650 @Override
4651 public boolean getDataEnabled(int subId) {
4652 return isUserDataEnabled(subId);
4653 }
4654
4655 /**
4656 * Get whether mobile data is enabled per user setting.
4657 *
4658 * There are other factors deciding whether mobile data is actually enabled, but they are
4659 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004660 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004661 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004662 *
4663 * @return {@code true} if data is enabled else {@code false}
4664 */
4665 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004666 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004667 try {
4668 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4669 null);
4670 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004671 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4672 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004673 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004674
4675 final long identity = Binder.clearCallingIdentity();
4676 try {
4677 int phoneId = mSubscriptionController.getPhoneId(subId);
4678 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4679 Phone phone = PhoneFactory.getPhone(phoneId);
4680 if (phone != null) {
4681 boolean retVal = phone.isUserDataEnabled();
4682 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4683 return retVal;
4684 } else {
4685 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4686 return false;
4687 }
4688 } finally {
4689 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004690 }
4691 }
4692
4693 /**
4694 * Get whether mobile data is enabled.
4695 *
4696 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4697 * whether mobile data is actually enabled.
4698 *
4699 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4700 *
4701 * @return {@code true} if data is enabled else {@code false}
4702 */
4703 @Override
4704 public boolean isDataEnabled(int subId) {
4705 try {
4706 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4707 null);
4708 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004709 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4710 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004711 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004712
4713 final long identity = Binder.clearCallingIdentity();
4714 try {
4715 int phoneId = mSubscriptionController.getPhoneId(subId);
4716 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4717 Phone phone = PhoneFactory.getPhone(phoneId);
4718 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08004719 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004720 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4721 return retVal;
4722 } else {
4723 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4724 return false;
4725 }
4726 } finally {
4727 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004728 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004729 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004730
4731 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004732 public int getCarrierPrivilegeStatus(int subId) {
4733 final Phone phone = getPhone(subId);
4734 if (phone == null) {
4735 loge("getCarrierPrivilegeStatus: Invalid subId");
4736 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4737 }
4738 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004739 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004740 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004741 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4742 }
4743 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004744 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004745 }
Junda Liu29340342014-07-10 15:23:27 -07004746
4747 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004748 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4749 final Phone phone = getPhone(subId);
4750 if (phone == null) {
4751 loge("getCarrierPrivilegeStatus: Invalid subId");
4752 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4753 }
4754 UiccProfile profile =
4755 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4756 if (profile == null) {
4757 loge("getCarrierPrivilegeStatus: No UICC");
4758 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4759 }
4760 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4761 }
4762
4763 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07004764 public int checkCarrierPrivilegesForPackage(String pkgName) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004765 final Phone defaultPhone = getDefaultPhone();
Junda Liu317d70b2016-03-08 09:33:53 -08004766 if (TextUtils.isEmpty(pkgName))
4767 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004768 UiccCard card = UiccController.getInstance().getUiccCard(defaultPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004769 if (card == null) {
4770 loge("checkCarrierPrivilegesForPackage: No UICC");
4771 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4772 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004773 return card.getCarrierPrivilegeStatus(defaultPhone.getContext().getPackageManager(),
4774 pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004775 }
4776
4777 @Override
4778 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004779 if (TextUtils.isEmpty(pkgName))
4780 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004781 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4782 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4783 UiccCard card = UiccController.getInstance().getUiccCard(i);
4784 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004785 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004786 continue;
4787 }
4788
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004789 result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004790 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4791 break;
4792 }
4793 }
4794
4795 return result;
Junda Liu29340342014-07-10 15:23:27 -07004796 }
Derek Tan89e89d42014-07-08 17:00:10 -07004797
4798 @Override
Junda Liue64de782015-04-16 17:19:16 -07004799 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4800 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4801 loge("phoneId " + phoneId + " is not valid.");
4802 return null;
4803 }
4804 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004805 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004806 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004807 return null ;
4808 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004809 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004810 }
4811
Amith Yamasani6e118872016-02-19 12:53:51 -08004812 @Override
4813 public List<String> getPackagesWithCarrierPrivileges() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004814 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08004815 List<String> privilegedPackages = new ArrayList<>();
4816 List<PackageInfo> packages = null;
4817 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4818 UiccCard card = UiccController.getInstance().getUiccCard(i);
4819 if (card == null) {
4820 // No UICC in that slot.
4821 continue;
4822 }
4823 if (card.hasCarrierPrivilegeRules()) {
4824 if (packages == null) {
4825 // Only check packages in user 0 for now
4826 packages = pm.getInstalledPackagesAsUser(
4827 PackageManager.MATCH_DISABLED_COMPONENTS
4828 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4829 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
4830 }
4831 for (int p = packages.size() - 1; p >= 0; p--) {
4832 PackageInfo pkgInfo = packages.get(p);
4833 if (pkgInfo != null && pkgInfo.packageName != null
4834 && card.getCarrierPrivilegeStatus(pkgInfo)
4835 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4836 privilegedPackages.add(pkgInfo.packageName);
4837 }
4838 }
4839 }
4840 }
4841 return privilegedPackages;
4842 }
4843
Wink Savilleb564aae2014-10-23 10:18:09 -07004844 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004845 final Phone phone = getPhone(subId);
4846 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004847 if (card == null) {
4848 loge("getIccId: No UICC");
4849 return null;
4850 }
4851 String iccId = card.getIccId();
4852 if (TextUtils.isEmpty(iccId)) {
4853 loge("getIccId: ICC ID is null or empty.");
4854 return null;
4855 }
4856 return iccId;
4857 }
4858
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004859 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004860 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4861 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004862 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4863 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004864
Malcolm Chend965c8b2018-02-28 15:00:40 -08004865 final long identity = Binder.clearCallingIdentity();
4866 try {
4867 final String iccId = getIccId(subId);
4868 final Phone phone = getPhone(subId);
4869 if (phone == null) {
4870 return false;
4871 }
4872 final String subscriberId = phone.getSubscriberId();
4873
4874 if (DBG_MERGE) {
4875 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4876 + subscriberId + " to " + number);
4877 }
4878
4879 if (TextUtils.isEmpty(iccId)) {
4880 return false;
4881 }
4882
4883 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4884
4885 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4886 if (alphaTag == null) {
4887 editor.remove(alphaTagPrefKey);
4888 } else {
4889 editor.putString(alphaTagPrefKey, alphaTag);
4890 }
4891
4892 // Record both the line number and IMSI for this ICCID, since we need to
4893 // track all merged IMSIs based on line number
4894 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4895 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4896 if (number == null) {
4897 editor.remove(numberPrefKey);
4898 editor.remove(subscriberPrefKey);
4899 } else {
4900 editor.putString(numberPrefKey, number);
4901 editor.putString(subscriberPrefKey, subscriberId);
4902 }
4903
4904 editor.commit();
4905 return true;
4906 } finally {
4907 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004908 }
Derek Tan7226c842014-07-02 17:42:23 -07004909 }
4910
4911 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004912 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004913 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004914 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004915 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004916 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004917 return null;
4918 }
Derek Tan97ebb422014-09-05 16:55:38 -07004919
Malcolm Chend965c8b2018-02-28 15:00:40 -08004920 final long identity = Binder.clearCallingIdentity();
4921 try {
4922 String iccId = getIccId(subId);
4923 if (iccId != null) {
4924 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4925 if (DBG_MERGE) {
4926 log("getLine1NumberForDisplay returning "
4927 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4928 }
4929 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004930 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004931 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4932 return null;
4933 } finally {
4934 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004935 }
Derek Tan7226c842014-07-02 17:42:23 -07004936 }
4937
4938 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004939 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004940 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004941 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004942 return null;
4943 }
Derek Tan97ebb422014-09-05 16:55:38 -07004944
Malcolm Chend965c8b2018-02-28 15:00:40 -08004945 final long identity = Binder.clearCallingIdentity();
4946 try {
4947 String iccId = getIccId(subId);
4948 if (iccId != null) {
4949 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4950 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4951 }
4952 return null;
4953 } finally {
4954 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004955 }
Derek Tan7226c842014-07-02 17:42:23 -07004956 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004957
4958 @Override
Jordan Liu9775d4b2019-05-06 14:45:15 -07004959 public String[] getMergedSubscriberIds(int subId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004960 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4961 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004962 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004963 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4964 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004965 return null;
4966 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004967
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004968 final long identity = Binder.clearCallingIdentity();
4969 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004970 final Context context = mApp;
Malcolm Chend965c8b2018-02-28 15:00:40 -08004971 final TelephonyManager tele = TelephonyManager.from(context);
4972 final SubscriptionManager sub = SubscriptionManager.from(context);
4973
4974 // Figure out what subscribers are currently active
4975 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
4976 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4977 // the process, where TelephonyManager was instantiated.
4978 // Otherwise AppOps check will fail.
4979
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004980 final int[] subIds = sub.getActiveSubscriptionIdList();
Jordan Liu9775d4b2019-05-06 14:45:15 -07004981 for (int id : subIds) {
4982 // Only consider subs which match the current subId
4983 // This logic can be simplified. See b/131189269 for progress.
4984 if (subId != id) {
4985 continue;
4986 }
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004987 activeSubscriberIds.add(tele.getSubscriberId(subId));
4988 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004989
4990 // First pass, find a number override for an active subscriber
4991 String mergeNumber = null;
4992 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
4993 for (String key : prefs.keySet()) {
4994 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
4995 final String subscriberId = (String) prefs.get(key);
4996 if (activeSubscriberIds.contains(subscriberId)) {
4997 final String iccId = key.substring(
4998 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
4999 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5000 mergeNumber = (String) prefs.get(numberKey);
5001 if (DBG_MERGE) {
5002 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5003 + " for active subscriber " + subscriberId);
5004 }
5005 if (!TextUtils.isEmpty(mergeNumber)) {
5006 break;
5007 }
5008 }
5009 }
5010 }
5011
5012 // Shortcut when no active merged subscribers
5013 if (TextUtils.isEmpty(mergeNumber)) {
5014 return null;
5015 }
5016
5017 // Second pass, find all subscribers under that line override
5018 final ArraySet<String> result = new ArraySet<>();
5019 for (String key : prefs.keySet()) {
5020 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5021 final String number = (String) prefs.get(key);
5022 if (mergeNumber.equals(number)) {
5023 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5024 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5025 final String subscriberId = (String) prefs.get(subscriberKey);
5026 if (!TextUtils.isEmpty(subscriberId)) {
5027 result.add(subscriberId);
5028 }
5029 }
5030 }
5031 }
5032
5033 final String[] resultArray = result.toArray(new String[result.size()]);
5034 Arrays.sort(resultArray);
5035 if (DBG_MERGE) {
5036 Slog.d(LOG_TAG,
5037 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5038 }
5039 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005040 } finally {
5041 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005042 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005043 }
5044
5045 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005046 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005047 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5048 subId, "setOperatorBrandOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005049
5050 final long identity = Binder.clearCallingIdentity();
5051 try {
5052 final Phone phone = getPhone(subId);
5053 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5054 } finally {
5055 Binder.restoreCallingIdentity(identity);
5056 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005057 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005058
5059 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005060 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005061 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5062 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005063 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005064
5065 final long identity = Binder.clearCallingIdentity();
5066 try {
5067 final Phone phone = getPhone(subId);
5068 if (phone == null) {
5069 return false;
5070 }
5071 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5072 cdmaNonRoamingList);
5073 } finally {
5074 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005075 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005076 }
5077
5078 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005079 @Deprecated
5080 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5081 enforceModifyPermission();
5082
5083 int returnValue = 0;
5084 try {
vagdevie435a3e2018-08-15 16:01:53 -07005085 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005086 if(result.exception == null) {
5087 if (result.result != null) {
5088 byte[] responseData = (byte[])(result.result);
5089 if(responseData.length > oemResp.length) {
5090 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5091 responseData.length + "bytes. Buffer Size is " +
5092 oemResp.length + "bytes.");
5093 }
5094 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5095 returnValue = responseData.length;
5096 }
5097 } else {
5098 CommandException ex = (CommandException) result.exception;
5099 returnValue = ex.getCommandError().ordinal();
5100 if(returnValue > 0) returnValue *= -1;
5101 }
5102 } catch (RuntimeException e) {
5103 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5104 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5105 if(returnValue > 0) returnValue *= -1;
5106 }
5107
5108 return returnValue;
5109 }
5110
5111 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005112 public void setRadioCapability(RadioAccessFamily[] rafs) {
5113 try {
5114 ProxyController.getInstance().setRadioCapability(rafs);
5115 } catch (RuntimeException e) {
5116 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5117 }
5118 }
5119
5120 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005121 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005122 Phone phone = PhoneFactory.getPhone(phoneId);
chen xufeeed752018-10-26 14:17:57 -07005123 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005124 if (phone == null) {
chen xufeeed752018-10-26 14:17:57 -07005125 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005126 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005127 final long identity = Binder.clearCallingIdentity();
5128 try {
chen xufeeed752018-10-26 14:17:57 -07005129 TelephonyPermissions
5130 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5131 mApp, phone.getSubId(), "getRadioAccessFamily");
5132 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005133 } finally {
5134 Binder.restoreCallingIdentity(identity);
5135 }
chen xufeeed752018-10-26 14:17:57 -07005136 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005137 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005138
5139 @Override
5140 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005141 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005142 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005143
5144 final long identity = Binder.clearCallingIdentity();
5145 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005146 ImsManager.getInstance(defaultPhone.getContext(),
5147 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005148 } finally {
5149 Binder.restoreCallingIdentity(identity);
5150 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005151 }
5152
5153 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005154 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005155 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00005156 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005157 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005158 return false;
5159 }
Svet Ganovb320e182015-04-16 12:30:10 -07005160
Malcolm Chend965c8b2018-02-28 15:00:40 -08005161 final long identity = Binder.clearCallingIdentity();
5162 try {
5163 // Check the user preference and the system-level IMS setting. Even if the user has
5164 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5165 // In the long run, we may instead need to check if there exists a connection service
5166 // which can support video calling.
5167 ImsManager imsManager =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005168 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005169 return imsManager.isVtEnabledByPlatform()
5170 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5171 && imsManager.isVtEnabledByUser();
5172 } finally {
5173 Binder.restoreCallingIdentity(identity);
5174 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005175 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005176
Andrew Leea1239f22015-03-02 17:44:07 -08005177 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08005178 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
5179 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5180 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5181 return false;
5182 }
5183
5184 final long identity = Binder.clearCallingIdentity();
5185 try {
5186 CarrierConfigManager configManager =
5187 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005188 return configManager.getConfigForSubId(subId)
Malcolm Chend965c8b2018-02-28 15:00:40 -08005189 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5190 } finally {
5191 Binder.restoreCallingIdentity(identity);
5192 }
Andrew Leea1239f22015-03-02 17:44:07 -08005193 }
5194
5195 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08005196 public boolean isWorldPhone(int subId, String callingPackage) {
5197 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5198 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5199 return false;
5200 }
5201
5202 final long identity = Binder.clearCallingIdentity();
5203 try {
5204 CarrierConfigManager configManager =
5205 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005206 return configManager.getConfigForSubId(subId)
Malcolm Chend965c8b2018-02-28 15:00:40 -08005207 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5208 } finally {
5209 Binder.restoreCallingIdentity(identity);
5210 }
Andrew Leea1239f22015-03-02 17:44:07 -08005211 }
5212
Andrew Lee9431b832015-03-09 18:46:45 -07005213 @Override
5214 public boolean isTtyModeSupported() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005215 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005216 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005217 }
5218
5219 @Override
5220 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005221 final long identity = Binder.clearCallingIdentity();
5222 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005223 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005224 } finally {
5225 Binder.restoreCallingIdentity(identity);
5226 }
Andrew Lee9431b832015-03-09 18:46:45 -07005227 }
5228
Hall Liuf6668912018-10-31 17:05:23 -07005229 /**
5230 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5231 * support for the feature and device firmware support.
5232 *
5233 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5234 */
5235 @Override
5236 public boolean isRttSupported(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005237 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005238 final Phone phone = getPhone(subscriptionId);
5239 if (phone == null) {
5240 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5241 return false;
5242 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005243 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005244 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chend965c8b2018-02-28 15:00:40 -08005245 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5246 boolean isDeviceSupported =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005247 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005248 return isCarrierSupported && isDeviceSupported;
5249 } finally {
5250 Binder.restoreCallingIdentity(identity);
5251 }
Hall Liu98187582018-01-22 19:15:32 -08005252 }
5253
Hall Liuf6668912018-10-31 17:05:23 -07005254 /**
5255 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
5256 * both also support RTT.
5257 */
5258 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005259 final long identity = Binder.clearCallingIdentity();
5260 try {
Hall Liuf6668912018-10-31 17:05:23 -07005261 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005262 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005263 } finally {
5264 Binder.restoreCallingIdentity(identity);
5265 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005266 }
5267
Sanket Padawe7310cc72015-01-14 09:53:20 -08005268 /**
5269 * Returns the unique device ID of phone, for example, the IMEI for
5270 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5271 *
5272 * <p>Requires Permission:
5273 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5274 */
5275 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005276 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005277 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005278 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005279 return null;
5280 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005281 int subId = phone.getSubId();
5282 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5283 mApp, subId, callingPackage, "getDeviceId")) {
5284 return null;
5285 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005286
5287 final long identity = Binder.clearCallingIdentity();
5288 try {
5289 return phone.getDeviceId();
5290 } finally {
5291 Binder.restoreCallingIdentity(identity);
5292 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005293 }
5294
Ping Sunc67b7c22016-03-02 19:16:45 +08005295 /**
5296 * {@hide}
5297 * Returns the IMS Registration Status on a particular subid
5298 *
5299 * @param subId
5300 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005301 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005302 Phone phone = getPhone(subId);
5303 if (phone != null) {
5304 return phone.isImsRegistered();
5305 } else {
5306 return false;
5307 }
5308 }
5309
Santos Cordon7a1885b2015-02-03 11:15:19 -08005310 @Override
5311 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005312 final long identity = Binder.clearCallingIdentity();
5313 try {
5314 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5315 } finally {
5316 Binder.restoreCallingIdentity(identity);
5317 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005318 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005319
Tyler Gunn327a9722019-04-03 15:28:53 -07005320 @Override
5321 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5322 final long identity = Binder.clearCallingIdentity();
5323 try {
5324 Phone phone = getPhone(subscriptionId);
5325 if (phone == null) {
5326 return null;
5327 }
5328 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5329 } finally {
5330 Binder.restoreCallingIdentity(identity);
5331 }
5332 }
5333
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005334 /**
5335 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005336 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005337 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005338 final long identity = Binder.clearCallingIdentity();
5339 try {
5340 Phone phone = getPhone(subId);
5341 if (phone != null) {
5342 return phone.isWifiCallingEnabled();
5343 } else {
5344 return false;
5345 }
5346 } finally {
5347 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005348 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005349 }
5350
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005351 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005352 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005353 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005354 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005355 final long identity = Binder.clearCallingIdentity();
5356 try {
5357 Phone phone = getPhone(subId);
5358 if (phone != null) {
5359 return phone.isVideoEnabled();
5360 } else {
5361 return false;
5362 }
5363 } finally {
5364 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005365 }
5366 }
5367
5368 /**
5369 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5370 * defined in {@link ImsRegistrationImplBase}.
5371 */
5372 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005373 final long identity = Binder.clearCallingIdentity();
5374 try {
5375 Phone phone = getPhone(subId);
5376 if (phone != null) {
5377 return phone.getImsRegistrationTech();
5378 } else {
5379 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5380 }
5381 } finally {
5382 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005383 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005384 }
5385
Stuart Scott8eef64f2015-04-08 15:13:54 -07005386 @Override
5387 public void factoryReset(int subId) {
5388 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005389 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5390 return;
5391 }
5392
Svet Ganovcc087f82015-05-12 20:35:54 -07005393 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005394
Svet Ganovcc087f82015-05-12 20:35:54 -07005395 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005396 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5397 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005398 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005399 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005400 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005401 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5402 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005403 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005404 // There has been issues when Sms raw table somehow stores orphan
5405 // fragments. They lead to garbled message when new fragments come
5406 // in and combined with those stale ones. In case this happens again,
5407 // user can reset all network settings which will clean up this table.
5408 cleanUpSmsRawTable(getDefaultPhone().getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07005409 } finally {
5410 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005411 }
5412 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005413
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005414 private void cleanUpSmsRawTable(Context context) {
5415 ContentResolver resolver = context.getContentResolver();
5416 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5417 resolver.delete(uri, null, null);
5418 }
5419
Narayan Kamath1c496c22015-04-16 14:40:19 +01005420 @Override
chen xu2e6dfec2019-01-21 23:31:38 -08005421 public String getSimLocaleForSubscriber(int subId) {
5422 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5423 final Phone phone = getPhone(subId);
5424 if (phone == null) {
5425 log("getSimLocaleForSubscriber, invalid subId");
Pengquan Meng9c291482019-01-28 16:26:29 -08005426 return null;
chen xu2e6dfec2019-01-21 23:31:38 -08005427 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005428 final long identity = Binder.clearCallingIdentity();
5429 try {
chen xu2e6dfec2019-01-21 23:31:38 -08005430 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5431 phone.getContext().getOpPackageName());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005432 // Try and fetch the locale from the carrier properties or from the SIM language
5433 // preferences (EF-PL and EF-LI)...
5434 final int mcc = info.getMcc();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005435 String simLanguage = null;
chen xu2e6dfec2019-01-21 23:31:38 -08005436 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5437 if (localeFromDefaultSim != null) {
5438 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5439 if (DBG) log("Using locale from subId: " + subId + " locale: "
5440 + localeFromDefaultSim);
5441 return localeFromDefaultSim.toLanguageTag();
5442 } else {
5443 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005444 }
5445 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005446
Malcolm Chend965c8b2018-02-28 15:00:40 -08005447 // The SIM language preferences only store a language (e.g. fr = French), not an
5448 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5449 // the SIM and carrier preferences does not include a country we add the country
5450 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005451 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005452 if (mccLocale != null) {
chen xu2e6dfec2019-01-21 23:31:38 -08005453 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005454 return mccLocale.toLanguageTag();
5455 }
5456
5457 if (DBG) log("No locale found - returning null");
5458 return null;
5459 } finally {
5460 Binder.restoreCallingIdentity(identity);
5461 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005462 }
5463
5464 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005465 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005466 }
5467
Malcolm Chend965c8b2018-02-28 15:00:40 -08005468 /**
5469 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5470 */
5471 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005472 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005473 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005474
Chenjie Yu1ba97252018-01-11 18:16:20 -08005475 private final ModemActivityInfo mLastModemActivityInfo =
5476 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
5477
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005478 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005479 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5480 * representing the state of the modem.
5481 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005482 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5483 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005484 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005485 */
5486 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005487 public void requestModemActivityInfo(ResultReceiver result) {
5488 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005489 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005490
5491 final long identity = Binder.clearCallingIdentity();
5492 try {
5493 ModemActivityInfo ret = null;
5494 synchronized (mLastModemActivityInfo) {
vagdevie435a3e2018-08-15 16:01:53 -07005495 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5496 CMD_GET_MODEM_ACTIVITY_INFO,
5497 null, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005498 if (isModemActivityInfoValid(info)) {
5499 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
5500 for (int i = 0; i < mergedTxTimeMs.length; i++) {
5501 mergedTxTimeMs[i] =
5502 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
5503 }
5504 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
5505 mLastModemActivityInfo.setSleepTimeMillis(
5506 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
5507 mLastModemActivityInfo.setIdleTimeMillis(
5508 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
5509 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
5510 mLastModemActivityInfo.setRxTimeMillis(
5511 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
5512 mLastModemActivityInfo.setEnergyUsed(
5513 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005514 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005515 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
5516 mLastModemActivityInfo.getSleepTimeMillis(),
5517 mLastModemActivityInfo.getIdleTimeMillis(),
5518 mLastModemActivityInfo.getTxTimeMillis(),
5519 mLastModemActivityInfo.getRxTimeMillis(),
5520 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005521 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005522 Bundle bundle = new Bundle();
5523 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
5524 result.send(0, bundle);
5525 } finally {
5526 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005527 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005528 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005529
Siddharth Rayf5d29552018-06-17 15:02:38 -07005530 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
5531 // less than total activity duration.
5532 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
5533 if (info == null) {
5534 return false;
5535 }
5536 int activityDurationMs =
5537 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
5538 int totalTxTimeMs = 0;
5539 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
5540 totalTxTimeMs += info.getTxTimeMillis()[i];
5541 }
5542 return (info.isValid()
5543 && (info.getSleepTimeMillis() <= activityDurationMs)
5544 && (info.getIdleTimeMillis() <= activityDurationMs)
5545 && (info.getRxTimeMillis() <= activityDurationMs)
5546 && (totalTxTimeMs <= activityDurationMs));
5547 }
5548
Jack Yu85bd38a2015-11-09 11:34:32 -08005549 /**
5550 * {@hide}
5551 * Returns the service state information on specified subscription.
5552 */
5553 @Override
5554 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005555 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005556 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08005557 return null;
5558 }
5559
Hall Liuf19c44f2018-11-27 14:38:17 -08005560 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
5561 LocationAccessPolicy.checkLocationPermission(mApp,
5562 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5563 .setCallingPackage(callingPackage)
5564 .setCallingPid(Binder.getCallingPid())
5565 .setCallingUid(Binder.getCallingUid())
5566 .setMethod("getServiceStateForSubscriber")
Hall Liu8b0cba22019-04-17 13:37:11 -07005567 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005568 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5569 .build());
5570
5571 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
5572 LocationAccessPolicy.checkLocationPermission(mApp,
5573 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5574 .setCallingPackage(callingPackage)
5575 .setCallingPid(Binder.getCallingPid())
5576 .setCallingUid(Binder.getCallingUid())
5577 .setMethod("getServiceStateForSubscriber")
Hall Liu8b0cba22019-04-17 13:37:11 -07005578 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005579 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5580 .build());
5581 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
5582 boolean hasFinePermission =
5583 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5584 boolean hasCoarsePermission =
5585 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5586
Malcolm Chend965c8b2018-02-28 15:00:40 -08005587 final long identity = Binder.clearCallingIdentity();
5588 try {
5589 final Phone phone = getPhone(subId);
5590 if (phone == null) {
5591 return null;
5592 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005593
Hall Liuf19c44f2018-11-27 14:38:17 -08005594 ServiceState ss = phone.getServiceState();
5595
5596 // Scrub out the location info in ServiceState depending on what level of access
5597 // the caller has.
5598 if (hasFinePermission) return ss;
5599 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
5600 return ss.sanitizeLocationInfo(true);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005601 } finally {
5602 Binder.restoreCallingIdentity(identity);
5603 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005604 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005605
5606 /**
5607 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
5608 *
5609 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5610 * voicemail ringtone.
5611 * @return The URI for the ringtone to play when receiving a voicemail from a specific
5612 * PhoneAccount.
5613 */
5614 @Override
5615 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005616 final long identity = Binder.clearCallingIdentity();
5617 try {
5618 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5619 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005620 phone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005621 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005622
Malcolm Chend965c8b2018-02-28 15:00:40 -08005623 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
5624 } finally {
5625 Binder.restoreCallingIdentity(identity);
5626 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005627 }
5628
5629 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005630 * Sets the per-account voicemail ringtone.
5631 *
5632 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5633 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5634 *
5635 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5636 * voicemail ringtone.
5637 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5638 * PhoneAccount.
5639 */
5640 @Override
5641 public void setVoicemailRingtoneUri(String callingPackage,
5642 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005643 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005644 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5645 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005646 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005647 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5648 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5649 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005650 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005651
5652 final long identity = Binder.clearCallingIdentity();
5653 try {
5654 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5655 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005656 phone = defaultPhone;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005657 }
5658 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5659 } finally {
5660 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005661 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005662 }
5663
5664 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005665 * Returns whether vibration is set for voicemail notification in Phone settings.
5666 *
5667 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5668 * voicemail vibration setting.
5669 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5670 */
5671 @Override
5672 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005673 final long identity = Binder.clearCallingIdentity();
5674 try {
5675 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5676 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005677 phone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005678 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005679
Malcolm Chend965c8b2018-02-28 15:00:40 -08005680 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5681 } finally {
5682 Binder.restoreCallingIdentity(identity);
5683 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005684 }
5685
Youhan Wange64578a2016-05-02 15:32:42 -07005686 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005687 * Sets the per-account voicemail vibration.
5688 *
5689 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5690 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5691 *
5692 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5693 * voicemail vibration setting.
5694 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5695 * specific PhoneAccount.
5696 */
5697 @Override
5698 public void setVoicemailVibrationEnabled(String callingPackage,
5699 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005700 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005701 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5702 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005703 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005704 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5705 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5706 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005707 }
5708
Malcolm Chend965c8b2018-02-28 15:00:40 -08005709 final long identity = Binder.clearCallingIdentity();
5710 try {
5711 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5712 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005713 phone = defaultPhone;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005714 }
5715 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5716 } finally {
5717 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005718 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005719 }
5720
5721 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005722 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5723 *
5724 * @throws SecurityException if the caller does not have the required permission
5725 */
Brad Ebinger4c460712018-10-01 10:40:55 -07005726 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005727 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger4c460712018-10-01 10:40:55 -07005728 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005729 }
5730
5731 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005732 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5733 * permission.
5734 *
5735 * @throws SecurityException if the caller does not have the required permission
5736 */
5737 private void enforceSendSmsPermission() {
5738 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5739 }
5740
5741 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005742 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005743 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005744 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005745 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005746 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005747 final long identity = Binder.clearCallingIdentity();
5748 try {
5749 ComponentName componentName =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005750 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005751 if (componentName == null) {
5752 throw new SecurityException(
5753 "Caller not current active visual voicemail package[null]");
5754 }
5755 String vvmPackage = componentName.getPackageName();
5756 if (!callingPackage.equals(vvmPackage)) {
5757 throw new SecurityException("Caller not current active visual voicemail package["
5758 + vvmPackage + "]");
5759 }
5760 } finally {
5761 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005762 }
5763 }
5764
5765 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005766 * Return the application ID for the app type.
5767 *
5768 * @param subId the subscription ID that this request applies to.
5769 * @param appType the uicc app type.
5770 * @return Application ID for specificied app type, or null if no uicc.
5771 */
5772 @Override
5773 public String getAidForAppType(int subId, int appType) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005774 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005775 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005776
5777 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005778 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005779 if (phone == null) {
5780 return null;
5781 }
5782 String aid = null;
5783 try {
5784 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5785 .getApplicationByType(appType).getAid();
5786 } catch (Exception e) {
5787 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5788 }
5789 return aid;
5790 } finally {
5791 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005792 }
Youhan Wange64578a2016-05-02 15:32:42 -07005793 }
5794
Youhan Wang4001d252016-05-11 10:29:41 -07005795 /**
5796 * Return the Electronic Serial Number.
5797 *
5798 * @param subId the subscription ID that this request applies to.
5799 * @return ESN or null if error.
5800 */
5801 @Override
5802 public String getEsn(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005803 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005804 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005805
5806 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005807 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005808 if (phone == null) {
5809 return null;
5810 }
5811 String esn = null;
5812 try {
5813 esn = phone.getEsn();
5814 } catch (Exception e) {
5815 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5816 }
5817 return esn;
5818 } finally {
5819 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005820 }
Youhan Wang4001d252016-05-11 10:29:41 -07005821 }
5822
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005823 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005824 * Return the Preferred Roaming List Version.
5825 *
5826 * @param subId the subscription ID that this request applies to.
5827 * @return PRLVersion or null if error.
5828 */
5829 @Override
5830 public String getCdmaPrlVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005831 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005832 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005833
5834 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005835 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005836 if (phone == null) {
5837 return null;
5838 }
5839 String cdmaPrlVersion = null;
5840 try {
5841 cdmaPrlVersion = phone.getCdmaPrlVersion();
5842 } catch (Exception e) {
5843 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5844 }
5845 return cdmaPrlVersion;
5846 } finally {
5847 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005848 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005849 }
5850
5851 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005852 * Get snapshot of Telephony histograms
5853 * @return List of Telephony histograms
5854 * @hide
5855 */
5856 @Override
5857 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005858 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5859 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005860
5861 final long identity = Binder.clearCallingIdentity();
5862 try {
5863 return RIL.getTelephonyRILTimingHistograms();
5864 } finally {
5865 Binder.restoreCallingIdentity(identity);
5866 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005867 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005868
5869 /**
5870 * {@hide}
Michele Berionne0963c862018-11-27 18:57:59 -08005871 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
5872 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005873 * Require system privileges. In the future we may add this to carrier APIs.
5874 *
Michele Berionne0963c862018-11-27 18:57:59 -08005875 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005876 */
5877 @Override
Michele Berionne0963c862018-11-27 18:57:59 -08005878 @TelephonyManager.SetCarrierRestrictionResult
5879 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005880 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005881 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005882
Michele Berionne0963c862018-11-27 18:57:59 -08005883 if (carrierRestrictionRules == null) {
5884 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08005885 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005886
Malcolm Chend965c8b2018-02-28 15:00:40 -08005887 final long identity = Binder.clearCallingIdentity();
5888 try {
Michele Berionne0963c862018-11-27 18:57:59 -08005889 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdevie435a3e2018-08-15 16:01:53 -07005890 workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005891 } finally {
5892 Binder.restoreCallingIdentity(identity);
5893 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005894 }
5895
5896 /**
5897 * {@hide}
Michele Berionne0963c862018-11-27 18:57:59 -08005898 * Get the allowed carrier list and the excluded carrier list, including the priority between
5899 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005900 * Require system privileges. In the future we may add this to carrier APIs.
5901 *
Michele Berionne0963c862018-11-27 18:57:59 -08005902 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07005903 */
5904 @Override
Michele Berionne0963c862018-11-27 18:57:59 -08005905 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger4c460712018-10-01 10:40:55 -07005906 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdevie435a3e2018-08-15 16:01:53 -07005907 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005908
5909 final long identity = Binder.clearCallingIdentity();
5910 try {
Michele Berionne0963c862018-11-27 18:57:59 -08005911 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
5912 if (response instanceof CarrierRestrictionRules) {
5913 return (CarrierRestrictionRules) response;
5914 }
5915 // Response is an Exception of some kind,
5916 // which is signalled to the user as a NULL retval
5917 return null;
5918 } catch (Exception e) {
5919 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
5920 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005921 } finally {
5922 Binder.restoreCallingIdentity(identity);
5923 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005924 }
5925
fionaxu59545b42016-05-25 15:53:37 -07005926 /**
5927 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5928 * @param subId the subscription ID that this action applies to.
5929 * @param enabled control enable or disable metered apns.
5930 * {@hide}
5931 */
5932 @Override
5933 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5934 enforceModifyPermission();
5935 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005936
5937 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005938 if (phone == null) {
5939 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5940 return;
5941 }
5942 try {
5943 phone.carrierActionSetMeteredApnsEnabled(enabled);
5944 } catch (Exception e) {
5945 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005946 } finally {
5947 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005948 }
5949 }
5950
5951 /**
5952 * Action set from carrier signalling broadcast receivers to enable/disable radio
5953 * @param subId the subscription ID that this action applies to.
5954 * @param enabled control enable or disable radio.
5955 * {@hide}
5956 */
5957 @Override
5958 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5959 enforceModifyPermission();
5960 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005961
5962 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005963 if (phone == null) {
5964 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5965 return;
5966 }
5967 try {
5968 phone.carrierActionSetRadioEnabled(enabled);
5969 } catch (Exception e) {
5970 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005971 } finally {
5972 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005973 }
5974 }
5975
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005976 /**
fionaxu8da9cb12017-05-23 15:02:46 -07005977 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
5978 * network status based on which carrier apps could apply actions accordingly,
5979 * enable/disable default url handler for example.
5980 *
5981 * @param subId the subscription ID that this action applies to.
5982 * @param report control start/stop reporting the default network status.
5983 * {@hide}
5984 */
5985 @Override
5986 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
5987 enforceModifyPermission();
5988 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005989
5990 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07005991 if (phone == null) {
5992 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
5993 return;
5994 }
5995 try {
5996 phone.carrierActionReportDefaultNetworkStatus(report);
5997 } catch (Exception e) {
5998 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005999 } finally {
6000 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006001 }
6002 }
6003
6004 /**
fionaxud9622282017-07-17 17:51:30 -07006005 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6006 * @param subId the subscription ID that this action applies to.
6007 * {@hide}
6008 */
6009 @Override
6010 public void carrierActionResetAll(int subId) {
6011 enforceModifyPermission();
6012 final Phone phone = getPhone(subId);
6013 if (phone == null) {
6014 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6015 return;
6016 }
6017 try {
6018 phone.carrierActionResetAll();
6019 } catch (Exception e) {
6020 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6021 }
6022 }
6023
6024 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006025 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6026 * bug report is being generated.
6027 */
6028 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006029 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006030 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6031 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006032 writer.println("Permission Denial: can't dump Phone from pid="
6033 + Binder.getCallingPid()
6034 + ", uid=" + Binder.getCallingUid()
6035 + "without permission "
6036 + android.Manifest.permission.DUMP);
6037 return;
6038 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006039 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006040 }
Jack Yueb89b242016-06-22 13:27:47 -07006041
Brad Ebingerdac2f002018-04-03 15:17:52 -07006042 @Override
6043 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6044 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6045 throws RemoteException {
6046 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
6047 }
6048
Jack Yueb89b242016-06-22 13:27:47 -07006049 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006050 * Get aggregated video call data usage since boot.
6051 *
6052 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6053 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006054 * {@hide}
6055 */
6056 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006057 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006058 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6059 null);
6060
Malcolm Chend965c8b2018-02-28 15:00:40 -08006061 final long identity = Binder.clearCallingIdentity();
6062 try {
6063 // NetworkStatsService keeps tracking the active network interface and identity. It
6064 // records the delta with the corresponding network identity.
6065 // We just return the total video call data usage snapshot since boot.
6066 Phone phone = getPhone(subId);
6067 if (phone != null) {
6068 return phone.getVtDataUsage(perUidStats);
6069 }
6070 return null;
6071 } finally {
6072 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006073 }
Jack Yueb89b242016-06-22 13:27:47 -07006074 }
Jack Yu75ab2952016-07-08 14:29:33 -07006075
6076 /**
6077 * Policy control of data connection. Usually used when data limit is passed.
6078 * @param enabled True if enabling the data, otherwise disabling.
6079 * @param subId Subscription index
6080 * {@hide}
6081 */
6082 @Override
6083 public void setPolicyDataEnabled(boolean enabled, int subId) {
6084 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08006085
6086 final long identity = Binder.clearCallingIdentity();
6087 try {
6088 Phone phone = getPhone(subId);
6089 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08006090 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chend965c8b2018-02-28 15:00:40 -08006091 }
6092 } finally {
6093 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006094 }
6095 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006096
6097 /**
6098 * Get Client request stats
6099 * @return List of Client Request Stats
6100 * @hide
6101 */
6102 @Override
6103 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006104 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006105 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006106 return null;
6107 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006108 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006109
Malcolm Chend965c8b2018-02-28 15:00:40 -08006110 final long identity = Binder.clearCallingIdentity();
6111 try {
6112 if (phone != null) {
6113 return phone.getClientRequestStats();
6114 }
6115
6116 return null;
6117 } finally {
6118 Binder.restoreCallingIdentity(identity);
6119 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006120 }
6121
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006122 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006123 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006124 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006125 }
Jack Yueb4124c2017-02-16 15:32:43 -08006126
6127 /**
Grace Chen70990072017-03-24 17:21:30 -07006128 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006129 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006130 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006131 * @param state State of SIM (power down, power up, pass through)
6132 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6133 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6134 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006135 *
6136 **/
6137 @Override
Grace Chen70990072017-03-24 17:21:30 -07006138 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006139 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006140 Phone phone = PhoneFactory.getPhone(slotIndex);
6141
vagdevie435a3e2018-08-15 16:01:53 -07006142 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6143
Malcolm Chend965c8b2018-02-28 15:00:40 -08006144 final long identity = Binder.clearCallingIdentity();
6145 try {
6146 if (phone != null) {
vagdevie435a3e2018-08-15 16:01:53 -07006147 phone.setSimPowerState(state, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08006148 }
6149 } finally {
6150 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006151 }
6152 }
Shuo Qiandd210312017-04-12 22:11:33 +00006153
Tyler Gunn65d45c22017-06-05 11:22:26 -07006154 private boolean isUssdApiAllowed(int subId) {
6155 CarrierConfigManager configManager =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006156 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006157 if (configManager == null) {
6158 return false;
6159 }
6160 PersistableBundle pb = configManager.getConfigForSubId(subId);
6161 if (pb == null) {
6162 return false;
6163 }
6164 return pb.getBoolean(
6165 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6166 }
6167
Shuo Qiandd210312017-04-12 22:11:33 +00006168 /**
6169 * Check if phone is in emergency callback mode
6170 * @return true if phone is in emergency callback mode
6171 * @param subId sub id
6172 */
goneil9c5f4872017-12-05 14:07:56 -08006173 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006174 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07006175 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006176 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08006177
6178 final long identity = Binder.clearCallingIdentity();
6179 try {
6180 if (phone != null) {
6181 return phone.isInEcm();
6182 } else {
6183 return false;
6184 }
6185 } finally {
6186 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006187 }
6188 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006189
6190 /**
6191 * Get the current signal strength information for the given subscription.
6192 * Because this information is not updated when the device is in a low power state
6193 * it should not be relied-upon to be current.
6194 * @param subId Subscription index
6195 * @return the most recent cached signal strength info from the modem
6196 */
6197 @Override
6198 public SignalStrength getSignalStrength(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08006199 final long identity = Binder.clearCallingIdentity();
6200 try {
6201 Phone p = getPhone(subId);
6202 if (p == null) {
6203 return null;
6204 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006205
Malcolm Chend965c8b2018-02-28 15:00:40 -08006206 return p.getSignalStrength();
6207 } finally {
6208 Binder.restoreCallingIdentity(identity);
6209 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006210 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006211
Pengquan Meng9140aec2018-08-22 14:49:57 -07006212 /**
chen xu907e5a22018-10-11 13:21:04 -07006213 * Get the current modem radio state for the given slot.
6214 * @param slotIndex slot index.
6215 * @param callingPackage the name of the package making the call.
6216 * @return the current radio power state from the modem
6217 */
6218 @Override
6219 public int getRadioPowerState(int slotIndex, String callingPackage) {
6220 Phone phone = PhoneFactory.getPhone(slotIndex);
6221 if (phone != null) {
6222 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6223 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
6224 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6225 }
6226
6227 final long identity = Binder.clearCallingIdentity();
6228 try {
6229 return phone.getRadioPowerState();
6230 } finally {
6231 Binder.restoreCallingIdentity(identity);
6232 }
6233 }
6234 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6235 }
6236
6237 /**
Pengquan Meng9140aec2018-08-22 14:49:57 -07006238 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6239 *
6240 * <p>Requires one of the following permissions:
6241 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6242 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6243 * privileges.
6244 *
6245 * @param subId subscription id
6246 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6247 * {@code false}.
6248 */
6249 @Override
6250 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006251 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6252 null /* message */);
6253
Pengquan Meng0c05b502018-09-06 09:59:22 -07006254 boolean isEnabled = false;
6255 final long identity = Binder.clearCallingIdentity();
Pengquan Meng9140aec2018-08-22 14:49:57 -07006256 try {
Pengquan Meng0c05b502018-09-06 09:59:22 -07006257 Phone phone = getPhone(subId);
6258 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng9140aec2018-08-22 14:49:57 -07006259 } catch (Exception e) {
6260 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6261 mApp, subId, "isDataRoamingEnabled");
Pengquan Meng0c05b502018-09-06 09:59:22 -07006262 } finally {
6263 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07006264 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07006265 return isEnabled;
Pengquan Meng9140aec2018-08-22 14:49:57 -07006266 }
6267
6268
6269 /**
6270 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6271 *
6272 * <p> Requires permission:
6273 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6274 * privileges.
6275 *
6276 * @param subId subscription id
6277 * @param isEnabled {@code true} means enable, {@code false} means disable.
6278 */
6279 @Override
6280 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006281 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6282 mApp, subId, "setDataRoamingEnabled");
6283
Pengquan Meng0c05b502018-09-06 09:59:22 -07006284 final long identity = Binder.clearCallingIdentity();
6285 try {
Pengquan Meng0c05b502018-09-06 09:59:22 -07006286 Phone phone = getPhone(subId);
6287 if (phone != null) {
6288 phone.setDataRoamingEnabled(isEnabled);
6289 }
6290 } finally {
6291 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07006292 }
6293 }
6294
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006295 @Override
Pengquan Meng312de0c2018-10-03 12:19:13 -07006296 public boolean isManualNetworkSelectionAllowed(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006297 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6298 mApp, subId, "isManualNetworkSelectionAllowed");
6299
Pengquan Meng312de0c2018-10-03 12:19:13 -07006300 boolean isAllowed = true;
6301 final long identity = Binder.clearCallingIdentity();
6302 try {
Pengquan Meng312de0c2018-10-03 12:19:13 -07006303 Phone phone = getPhone(subId);
6304 if (phone != null) {
6305 isAllowed = phone.isCspPlmnEnabled();
6306 }
6307 } finally {
6308 Binder.restoreCallingIdentity(identity);
6309 }
6310 return isAllowed;
6311 }
6312
6313 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006314 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu67997952019-04-22 15:10:43 -07006315 boolean hasReadPermission = false;
Jordan Liu53fdb782019-02-12 17:54:02 -08006316 try {
6317 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu67997952019-04-22 15:10:43 -07006318 hasReadPermission = true;
Jordan Liu53fdb782019-02-12 17:54:02 -08006319 } catch (SecurityException e) {
6320 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6321 // has carrier privileges on an active UICC
6322 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6323 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu67997952019-04-22 15:10:43 -07006324 throw new SecurityException("Caller does not have permission.");
Jordan Liu53fdb782019-02-12 17:54:02 -08006325 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006326 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006327
6328 final long identity = Binder.clearCallingIdentity();
6329 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006330 UiccController uiccController = UiccController.getInstance();
6331 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu67997952019-04-22 15:10:43 -07006332 if (hasReadPermission) {
6333 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006334 }
Jordan Liu67997952019-04-22 15:10:43 -07006335
6336 // Remove private info if the caller doesn't have access
6337 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6338 for (UiccCardInfo cardInfo : cardInfos) {
6339 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6340 // is available
6341 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
6342 if (card == null || card.getUiccProfile() == null) {
6343 // assume no access if the card or profile is unavailable
6344 filteredInfos.add(cardInfo.getUnprivileged());
6345 continue;
6346 }
6347 UiccProfile profile = card.getUiccProfile();
6348 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6349 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6350 filteredInfos.add(cardInfo);
6351 } else {
6352 filteredInfos.add(cardInfo.getUnprivileged());
6353 }
6354 }
6355 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08006356 } finally {
6357 Binder.restoreCallingIdentity(identity);
6358 }
6359 }
6360
6361 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006362 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger4c460712018-10-01 10:40:55 -07006363 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006364
Malcolm Chend965c8b2018-02-28 15:00:40 -08006365 final long identity = Binder.clearCallingIdentity();
6366 try {
6367 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6368 if (slots == null) {
6369 Rlog.i(LOG_TAG, "slots is null.");
6370 return null;
6371 }
6372
6373 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6374 for (int i = 0; i < slots.length; i++) {
6375 UiccSlot slot = slots[i];
6376 if (slot == null) {
6377 continue;
6378 }
6379
6380 String cardId;
6381 UiccCard card = slot.getUiccCard();
6382 if (card != null) {
6383 cardId = card.getCardId();
6384 } else {
6385 cardId = slot.getIccId();
6386 }
6387
Jordan Liu857451f2019-05-09 16:35:35 -07006388 if (cardId != null) {
6389 // if cardId is an ICCID, strip off trailing Fs before exposing to user
6390 // if cardId is an EID, it's all digits so this is fine
6391 cardId = IccUtils.stripTrailingFs(cardId);
6392 }
6393
Malcolm Chend965c8b2018-02-28 15:00:40 -08006394 int cardState = 0;
6395 switch (slot.getCardState()) {
6396 case CARDSTATE_ABSENT:
6397 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6398 break;
6399 case CARDSTATE_PRESENT:
6400 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6401 break;
6402 case CARDSTATE_ERROR:
6403 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6404 break;
6405 case CARDSTATE_RESTRICTED:
6406 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6407 break;
6408 default:
6409 break;
6410
6411 }
6412
6413 infos[i] = new UiccSlotInfo(
6414 slot.isActive(),
6415 slot.isEuicc(),
6416 cardId,
6417 cardState,
6418 slot.getPhoneId(),
Jordan Liuef65d872019-02-14 12:56:40 -08006419 slot.isExtendedApduSupported(),
6420 slot.isRemovable());
Malcolm Chend965c8b2018-02-28 15:00:40 -08006421 }
6422 return infos;
6423 } finally {
6424 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006425 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006426 }
6427
6428 @Override
6429 public boolean switchSlots(int[] physicalSlots) {
6430 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08006431
6432 final long identity = Binder.clearCallingIdentity();
6433 try {
6434 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6435 } finally {
6436 Binder.restoreCallingIdentity(identity);
6437 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006438 }
Jack Yu4c988042018-02-27 15:30:01 -08006439
6440 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006441 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006442 final long identity = Binder.clearCallingIdentity();
6443 try {
6444 return UiccController.getInstance().getCardIdForDefaultEuicc();
6445 } finally {
6446 Binder.restoreCallingIdentity(identity);
6447 }
6448 }
6449
6450 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006451 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6452 enforceModifyPermission();
6453 final Phone phone = getPhone(subId);
6454 if (phone == null) {
6455 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6456 return;
6457 }
6458
Malcolm Chend965c8b2018-02-28 15:00:40 -08006459 final long identity = Binder.clearCallingIdentity();
6460 try {
6461 phone.setRadioIndicationUpdateMode(filters, mode);
6462 } finally {
6463 Binder.restoreCallingIdentity(identity);
6464 }
Jack Yu4c988042018-02-27 15:30:01 -08006465 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006466
6467 /**
goneil47ffb6e2018-04-06 15:40:58 -07006468 * A test API to reload the UICC profile.
6469 *
6470 * <p>Requires that the calling app has permission
6471 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6472 * @hide
6473 */
6474 @Override
6475 public void refreshUiccProfile(int subId) {
6476 enforceModifyPermission();
6477
6478 final long identity = Binder.clearCallingIdentity();
6479 try {
6480 Phone phone = getPhone(subId);
6481 if (phone == null) {
6482 return;
6483 }
6484 UiccCard uiccCard = phone.getUiccCard();
6485 if (uiccCard == null) {
6486 return;
6487 }
6488 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6489 if (uiccProfile == null) {
6490 return;
6491 }
6492 uiccProfile.refresh();
6493 } finally {
6494 Binder.restoreCallingIdentity(identity);
6495 }
6496 }
6497
6498 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006499 * Returns false if the mobile data is disabled by default, otherwise return true.
6500 */
6501 private boolean getDefaultDataEnabled() {
6502 return "true".equalsIgnoreCase(
6503 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
6504 }
6505
6506 /**
6507 * Returns true if the data roaming is enabled by default, i.e the system property
6508 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
6509 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
6510 */
6511 private boolean getDefaultDataRoamingEnabled(int subId) {
6512 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006513 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006514 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
6515 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
6516 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
6517 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
6518 return isDataRoamingEnabled;
6519 }
6520
6521 /**
6522 * Returns the default network type for the given {@code subId}, if the default network type is
6523 * not set, return {@link Phone#PREFERRED_NT_MODE}.
6524 */
6525 private int getDefaultNetworkType(int subId) {
6526 return Integer.parseInt(
6527 TelephonyManager.getTelephonyProperty(
6528 mSubscriptionController.getPhoneId(subId),
6529 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
6530 String.valueOf(Phone.PREFERRED_NT_MODE)));
6531 }
fionaxua13278b2018-03-21 00:08:13 -07006532
6533 @Override
6534 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
6535 gid1, String gid2, String plmn, String spn) {
6536 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08006537
6538 final long identity = Binder.clearCallingIdentity();
6539 try {
6540 final Phone phone = getPhone(subId);
6541 if (phone == null) {
6542 loge("setCarrierTestOverride fails with invalid subId: " + subId);
6543 return;
6544 }
6545 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
6546 } finally {
6547 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006548 }
fionaxua13278b2018-03-21 00:08:13 -07006549 }
6550
6551 @Override
6552 public int getCarrierIdListVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07006553 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chend965c8b2018-02-28 15:00:40 -08006554
6555 final long identity = Binder.clearCallingIdentity();
6556 try {
6557 final Phone phone = getPhone(subId);
6558 if (phone == null) {
6559 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
6560 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
6561 }
6562 return phone.getCarrierIdListVersion();
6563 } finally {
6564 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006565 }
fionaxua13278b2018-03-21 00:08:13 -07006566 }
Malcolm Chenf144d942018-08-14 16:00:53 -07006567
6568 @Override
6569 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
6570 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6571 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
6572 return -1;
6573 }
6574
6575 final long identity = Binder.clearCallingIdentity();
6576 try {
6577 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
6578 } finally {
6579 Binder.restoreCallingIdentity(identity);
6580 }
6581 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07006582
6583 @Override
6584 public int getCdmaRoamingMode(int subId) {
6585 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6586 mApp, subId, "getCdmaRoamingMode");
6587
6588 final long identity = Binder.clearCallingIdentity();
6589 try {
6590 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
6591 } finally {
6592 Binder.restoreCallingIdentity(identity);
6593 }
6594 }
6595
6596 @Override
6597 public boolean setCdmaRoamingMode(int subId, int mode) {
6598 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6599 mApp, subId, "setCdmaRoamingMode");
6600
6601 final long identity = Binder.clearCallingIdentity();
6602 try {
6603 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
6604 } finally {
6605 Binder.restoreCallingIdentity(identity);
6606 }
6607 }
6608
6609 @Override
6610 public boolean setCdmaSubscriptionMode(int subId, int mode) {
6611 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6612 mApp, subId, "setCdmaSubscriptionMode");
6613
6614 final long identity = Binder.clearCallingIdentity();
6615 try {
6616 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
6617 } finally {
6618 Binder.restoreCallingIdentity(identity);
6619 }
6620 }
chen xu7ee67862018-10-30 22:27:10 -07006621
sqian2fff4a32018-11-05 14:18:37 -08006622 private void ensureUserRunning(int userId) {
6623 if (!mUserManager.isUserRunning(userId)) {
6624 throw new IllegalStateException("User " + userId + " does not exist or not running");
6625 }
6626 }
6627
6628 /**
6629 * Returns a list of SMS apps on a given user.
6630 *
6631 * Only the shell user (UID 2000 or 0) can call it.
6632 * Target user must be running.
6633 */
6634 @Override
6635 public String[] getSmsApps(int userId) {
6636 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
6637 ensureUserRunning(userId);
6638
6639 final Collection<SmsApplicationData> apps =
6640 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
6641
6642 String[] ret = new String[apps.size()];
6643 int i = 0;
6644 for (SmsApplicationData app : apps) {
6645 ret[i++] = app.mPackageName;
6646 }
6647 return ret;
6648 }
6649
6650 /**
6651 * Returns the default SMS app package name on a given user.
6652 *
6653 * Only the shell user (UID 2000 or 0) can call it.
6654 * Target user must be running.
6655 */
6656 @Override
6657 public String getDefaultSmsApp(int userId) {
6658 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
6659 ensureUserRunning(userId);
6660
6661 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
6662 /* updateIfNeeded= */ true, userId);
6663 return cn == null ? null : cn.getPackageName();
6664 }
6665
6666 /**
6667 * Set a package as the default SMS app on a given user.
6668 *
6669 * Only the shell user (UID 2000 or 0) can call it.
6670 * Target user must be running.
6671 */
6672 @Override
6673 public void setDefaultSmsApp(int userId, String packageName) {
6674 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
6675 ensureUserRunning(userId);
6676
6677 boolean found = false;
6678 for (String pkg : getSmsApps(userId)) {
6679 if (TextUtils.equals(packageName, pkg)) {
6680 found = true;
6681 break;
6682 }
6683 }
6684 if (!found) {
6685 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
6686 }
6687
6688 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
6689 }
6690
chen xu7ee67862018-10-30 22:27:10 -07006691 @Override
sqian65eefe12019-02-22 15:55:18 -08006692 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
sqian04b86072018-11-07 14:02:21 -08006693 String callingPackage) {
sqian03bca152018-12-05 18:48:28 -08006694 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
sqian65eefe12019-02-22 15:55:18 -08006695 mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) {
sqian03bca152018-12-05 18:48:28 -08006696 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6697 }
6698 final long identity = Binder.clearCallingIdentity();
6699 try {
sqian991b35e2018-12-12 16:48:18 -08006700 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
6701 for (Phone phone: PhoneFactory.getPhones()) {
6702 if (phone.getEmergencyNumberTracker() != null
6703 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
6704 emergencyNumberListInternal.put(
6705 phone.getSubId(),
6706 phone.getEmergencyNumberTracker().getEmergencyNumberList());
6707 }
sqian03bca152018-12-05 18:48:28 -08006708 }
sqian991b35e2018-12-12 16:48:18 -08006709 return emergencyNumberListInternal;
sqian03bca152018-12-05 18:48:28 -08006710 } finally {
6711 Binder.restoreCallingIdentity(identity);
6712 }
sqian04b86072018-11-07 14:02:21 -08006713 }
6714
6715 @Override
sqian65eefe12019-02-22 15:55:18 -08006716 public boolean isEmergencyNumber(String number, boolean exactMatch) {
sqian03bca152018-12-05 18:48:28 -08006717 final Phone defaultPhone = getDefaultPhone();
6718 if (!exactMatch) {
6719 TelephonyPermissions
6720 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian65eefe12019-02-22 15:55:18 -08006721 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian03bca152018-12-05 18:48:28 -08006722 }
6723 final long identity = Binder.clearCallingIdentity();
6724 try {
sqian991b35e2018-12-12 16:48:18 -08006725 for (Phone phone: PhoneFactory.getPhones()) {
6726 if (phone.getEmergencyNumberTracker() != null
6727 && phone.getEmergencyNumberTracker() != null) {
6728 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
6729 number, exactMatch)) {
6730 return true;
sqian03bca152018-12-05 18:48:28 -08006731 }
6732 }
sqian03bca152018-12-05 18:48:28 -08006733 }
6734 return false;
6735 } finally {
6736 Binder.restoreCallingIdentity(identity);
6737 }
6738 }
6739
sqian9d4df8b2019-01-15 18:32:07 -08006740 /**
6741 * Update emergency number list for test mode.
6742 */
6743 @Override
6744 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
6745 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6746 "updateEmergencyNumberListTestMode");
6747
6748 final long identity = Binder.clearCallingIdentity();
6749 try {
6750 for (Phone phone: PhoneFactory.getPhones()) {
6751 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6752 if (tracker != null) {
6753 tracker.executeEmergencyNumberTestModeCommand(action, num);
6754 }
6755 }
6756 } finally {
6757 Binder.restoreCallingIdentity(identity);
6758 }
6759 }
6760
6761 /**
6762 * Get the full emergency number list for test mode.
6763 */
6764 @Override
6765 public List<String> getEmergencyNumberListTestMode() {
6766 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6767 "getEmergencyNumberListTestMode");
6768
6769 final long identity = Binder.clearCallingIdentity();
6770 try {
6771 Set<String> emergencyNumbers = new HashSet<>();
6772 for (Phone phone: PhoneFactory.getPhones()) {
6773 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6774 if (tracker != null) {
6775 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
6776 emergencyNumbers.add(num.getNumber());
6777 }
6778 }
6779 }
6780 return new ArrayList<>(emergencyNumbers);
6781 } finally {
6782 Binder.restoreCallingIdentity(identity);
6783 }
6784 }
6785
sqian04b86072018-11-07 14:02:21 -08006786 @Override
chen xu7ee67862018-10-30 22:27:10 -07006787 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
6788 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
6789 Phone phone = getPhone(subId);
6790 if (phone == null) {
6791 return null;
6792 }
6793 final long identity = Binder.clearCallingIdentity();
6794 try {
6795 UiccProfile profile = UiccController.getInstance()
6796 .getUiccProfileForPhone(phone.getPhoneId());
6797 if (profile != null) {
6798 return profile.getCertsFromCarrierPrivilegeAccessRules();
6799 }
6800 } finally {
6801 Binder.restoreCallingIdentity(identity);
6802 }
6803 return null;
6804 }
Malcolm Chen509b5b72019-01-15 20:22:16 -08006805
6806 /**
6807 * Enable or disable a modem stack.
6808 */
6809 @Override
6810 public boolean enableModemForSlot(int slotIndex, boolean enable) {
6811 enforceModifyPermission();
6812
6813 final long identity = Binder.clearCallingIdentity();
6814 try {
6815 Phone phone = PhoneFactory.getPhone(slotIndex);
6816 if (phone == null) {
6817 return false;
6818 } else {
6819 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
6820 }
6821 } finally {
6822 Binder.restoreCallingIdentity(identity);
6823 }
6824 }
Micheled3107c52018-12-21 15:00:11 -08006825
Malcolm Chen33f55e12019-03-27 18:34:05 -07006826 /**
6827 * Whether a modem stack is enabled or not.
6828 */
6829 @Override
6830 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage) {
6831 Phone phone = PhoneFactory.getPhone(slotIndex);
6832 if (phone == null) return false;
6833
6834 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6835 mApp, phone.getSubId(), callingPackage, "isModemEnabledForSlot")) {
6836 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6837 }
6838
6839 final long identity = Binder.clearCallingIdentity();
6840 try {
Nazanin Bakhshi1f78d7d2019-04-29 17:29:44 -07006841 try {
6842 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
6843 } catch (NoSuchElementException ex) {
6844 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
6845 }
Malcolm Chen33f55e12019-03-27 18:34:05 -07006846 } finally {
6847 Binder.restoreCallingIdentity(identity);
6848 }
6849 }
6850
Micheled3107c52018-12-21 15:00:11 -08006851 @Override
Michele2fb0f222019-03-19 14:58:42 -07006852 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Micheled3107c52018-12-21 15:00:11 -08006853 enforceModifyPermission();
6854
6855 final long identity = Binder.clearCallingIdentity();
6856 try {
6857 mTelephonySharedPreferences.edit()
Michele2fb0f222019-03-19 14:58:42 -07006858 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Micheled3107c52018-12-21 15:00:11 -08006859 .commit();
6860 } finally {
6861 Binder.restoreCallingIdentity(identity);
6862 }
6863 }
6864
6865 @Override
Michele2fb0f222019-03-19 14:58:42 -07006866 @TelephonyManager.IsMultiSimSupportedResult
6867 public int isMultiSimSupported(String callingPackage) {
Michelebcb01bc2019-02-04 11:36:23 -08006868 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Michele2fb0f222019-03-19 14:58:42 -07006869 getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) {
6870 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michelebcb01bc2019-02-04 11:36:23 -08006871 }
Micheled3107c52018-12-21 15:00:11 -08006872
6873 final long identity = Binder.clearCallingIdentity();
6874 try {
Michele2fb0f222019-03-19 14:58:42 -07006875 return isMultiSimSupportedInternal();
Micheled3107c52018-12-21 15:00:11 -08006876 } finally {
6877 Binder.restoreCallingIdentity(identity);
6878 }
6879 }
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006880
Michele2fb0f222019-03-19 14:58:42 -07006881 @TelephonyManager.IsMultiSimSupportedResult
6882 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08006883 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
6884 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
6885 if (numPhysicalSlots < 2) {
Michele2fb0f222019-03-19 14:58:42 -07006886 loge("isMultiSimSupportedInternal: requires at least 2 cards");
6887 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006888 }
6889 // Check if the hardware supports multisim functionality. If usage of multisim is not
6890 // supported by the modem, indicate that it is restricted.
6891 PhoneCapability staticCapability =
6892 mPhoneConfigurationManager.getStaticPhoneCapability();
6893 if (staticCapability == null) {
Michele2fb0f222019-03-19 14:58:42 -07006894 loge("isMultiSimSupportedInternal: no static configuration available");
6895 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006896 }
6897 if (staticCapability.logicalModemList.size() < 2) {
Michele2fb0f222019-03-19 14:58:42 -07006898 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
6899 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006900 }
6901 // Check if support of multiple SIMs is restricted by carrier
6902 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele2fb0f222019-03-19 14:58:42 -07006903 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08006904 }
6905
Michele2fb0f222019-03-19 14:58:42 -07006906 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08006907 }
6908
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006909 /**
6910 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi814dc222019-03-01 11:56:08 -08006911 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
6912 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
6913 * or carrier privileges
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006914 * @param numOfSims number of active sims we want to switch to
6915 */
6916 @Override
6917 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi814dc222019-03-01 11:56:08 -08006918 if (numOfSims == 1) {
6919 enforceModifyPermission();
6920 } else {
6921 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6922 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
6923 }
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006924 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08006925
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006926 try {
Michele30b57b22019-03-01 12:01:14 -08006927 //only proceed if multi-sim is not restricted
Michele2fb0f222019-03-19 14:58:42 -07006928 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08006929 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
6930 return;
6931 }
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006932 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
6933 } finally {
6934 Binder.restoreCallingIdentity(identity);
6935 }
6936 }
6937
6938 /**
Nazanin Bakhshicd417af2019-01-30 10:52:09 -08006939 * Get whether reboot is required or not after making changes to modem configurations.
Nazanin Bakhshi4a68f5f2019-02-08 14:31:19 -08006940 * Return value defaults to true
Nazanin Bakhshicd417af2019-01-30 10:52:09 -08006941 */
6942 @Override
6943 public boolean isRebootRequiredForModemConfigChange() {
6944 enforceReadPrivilegedPermission("isRebootRequiredForModemConfigChange");
6945 final long identity = Binder.clearCallingIdentity();
6946 try {
6947 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
6948 } finally {
6949 Binder.restoreCallingIdentity(identity);
6950 }
6951 }
6952
Pengquan Meng92d253b2019-02-06 11:12:53 -08006953 private void updateModemStateMetrics() {
6954 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
6955 // TODO: check the state for each modem if the api is ready.
6956 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
6957 }
6958
Pengquan Meng3aceaec2019-01-23 11:16:29 -08006959 @Override
6960 public int[] getSlotsMapping() {
6961 enforceReadPrivilegedPermission("getSlotsMapping");
6962
6963 final long identity = Binder.clearCallingIdentity();
6964 try {
6965 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
6966 // All logical slots should have a mapping to a physical slot.
6967 int[] logicalSlotsMapping = new int[phoneCount];
6968 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
6969 for (int i = 0; i < slotInfos.length; i++) {
6970 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
6971 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
6972 }
6973 }
6974 return logicalSlotsMapping;
6975 } finally {
6976 Binder.restoreCallingIdentity(identity);
6977 }
6978 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08006979
6980 /**
6981 * Get the IRadio HAL Version
6982 */
6983 @Override
6984 public int getRadioHalVersion() {
6985 Phone phone = getDefaultPhone();
6986 if (phone == null) return -1;
6987 HalVersion hv = phone.getHalVersion();
6988 if (hv.equals(HalVersion.UNKNOWN)) return -1;
6989 return hv.major * 100 + hv.minor;
6990 }
Malcolm Chen460810d2019-04-10 18:25:07 -07006991
6992 /**
Malcolm Chen29739692019-04-18 13:51:02 -07006993 * Return whether data is enabled for certain APN type. This will tell if framework will accept
6994 * corresponding network requests on a subId.
6995 *
6996 * Data is enabled if:
Malcolm Chen460810d2019-04-10 18:25:07 -07006997 * 1) user data is turned on, or
Malcolm Chen29739692019-04-18 13:51:02 -07006998 * 2) APN is un-metered for this subscription, or
6999 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
7000 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on.
7001 *
7002 * @return whether data is allowed for a apn type.
7003 *
7004 * @hide
Malcolm Chen460810d2019-04-10 18:25:07 -07007005 */
7006 @Override
Malcolm Chen29739692019-04-18 13:51:02 -07007007 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Malcolm Chen460810d2019-04-10 18:25:07 -07007008 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Malcolm Chen29739692019-04-18 13:51:02 -07007009 mApp, subId, callingPackage, "isDataEnabledForApn")) {
7010 throw new SecurityException("Needs READ_PHONE_STATE for isDataEnabledForApn");
Malcolm Chen460810d2019-04-10 18:25:07 -07007011 }
7012
7013 // Now that all security checks passes, perform the operation as ourselves.
7014 final long identity = Binder.clearCallingIdentity();
7015 try {
7016 Phone phone = getPhone(subId);
7017 if (phone == null) return false;
7018
Jack Yu40306fc2019-05-13 16:54:09 -07007019 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chen29739692019-04-18 13:51:02 -07007020 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7021 } finally {
7022 Binder.restoreCallingIdentity(identity);
7023 }
7024 }
7025
7026 @Override
Jack Yu40306fc2019-05-13 16:54:09 -07007027 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chen29739692019-04-18 13:51:02 -07007028 enforceReadPrivilegedPermission("isApnMetered");
7029
7030 // Now that all security checks passes, perform the operation as ourselves.
7031 final long identity = Binder.clearCallingIdentity();
7032 try {
7033 Phone phone = getPhone(subId);
7034 if (phone == null) return true; // By default return true.
7035
Jack Yu40306fc2019-05-13 16:54:09 -07007036 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chen460810d2019-04-10 18:25:07 -07007037 } finally {
7038 Binder.restoreCallingIdentity(identity);
7039 }
7040 }
chen xu7bc8e072019-05-28 15:20:57 -07007041
7042 @Override
Brad Ebinger5ff97f62019-04-23 16:31:13 -07007043 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
7044 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
7045 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
7046 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
7047 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
7048 }
7049 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
7050 Intent intent = new Intent();
7051 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
7052 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7053 // Bring up choose default SMS subscription dialog right now
7054 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
7055 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
7056 mApp.startActivity(intent);
7057 }
7058
7059 @Override
chen xu7bc8e072019-05-28 15:20:57 -07007060 public String getMmsUAProfUrl(int subId) {
7061 //TODO investigate if this API should require proper permission check in R b/133791609
7062 final long identity = Binder.clearCallingIdentity();
7063 try {
7064 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7065 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
7066 } finally {
7067 Binder.restoreCallingIdentity(identity);
7068 }
7069 }
7070
7071 @Override
7072 public String getMmsUserAgent(int subId) {
7073 //TODO investigate if this API should require proper permission check in R b/133791609
7074 final long identity = Binder.clearCallingIdentity();
7075 try {
7076 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7077 .getString(com.android.internal.R.string.config_mms_user_agent);
7078 } finally {
7079 Binder.restoreCallingIdentity(identity);
7080 }
7081 }
Jack Yuea3bebe2019-05-28 16:12:25 -07007082
7083 @Override
7084 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
7085 enforceModifyPermission();
7086
7087 // Now that all security checks passes, perform the operation as ourselves.
7088 final long identity = Binder.clearCallingIdentity();
7089 try {
7090 Phone phone = getPhone(subId);
7091 if (phone == null) return false;
7092
7093 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
7094 } finally {
7095 Binder.restoreCallingIdentity(identity);
7096 }
7097 }
7098
7099 @Override
7100 public boolean isDataAllowedInVoiceCall(int subId) {
7101 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
7102
7103 // Now that all security checks passes, perform the operation as ourselves.
7104 final long identity = Binder.clearCallingIdentity();
7105 try {
7106 Phone phone = getPhone(subId);
7107 if (phone == null) return false;
7108
7109 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
7110 } finally {
7111 Binder.restoreCallingIdentity(identity);
7112 }
7113 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007114}