blob: 678f661639c692e81e65f6b8cc75b018b0b7cd76 [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 *
Nathan Haroldec184742019-07-10 17:04:16 -07002017 * This call MUST be invoked before clearing the calling UID.
2018 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002019 * @return target SDK if the package is found or INT_MAX.
2020 */
2021 private int getTargetSdk(String packageName) {
2022 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002023 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
2024 packageName, 0, UserHandle.getUserId(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002025 if (ai != null) return ai.targetSdkVersion;
2026 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002027 loge("Failed to get package info for pkg="
2028 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002029 }
2030 return Integer.MAX_VALUE;
2031 }
2032
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002033 @Override
2034 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07002035 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
2036 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002037 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2038 throw new SecurityException(
2039 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2040 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002041
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002042 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
2043 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2044 return null;
2045 }
Svetoslav64fad262015-04-14 14:35:21 -07002046
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002047 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002048
Nathan Haroldf180aac2018-06-01 18:43:55 -07002049 List<CellInfo> info = getAllCellInfo(callingPackage);
2050 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002051
Nathan Haroldf180aac2018-06-01 18:43:55 -07002052 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2053 for (CellInfo ci : info) {
2054 if (ci instanceof CellInfoGsm) {
2055 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2056 } else if (ci instanceof CellInfoWcdma) {
2057 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2058 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002059 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002060 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002061 }
2062
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002063 private List<CellInfo> getCachedCellInfo() {
2064 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2065 for (Phone phone : PhoneFactory.getPhones()) {
2066 List<CellInfo> info = phone.getAllCellInfo();
2067 if (info != null) cellInfos.addAll(info);
2068 }
2069 return cellInfos;
2070 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002071
2072 @Override
Svetoslav64fad262015-04-14 14:35:21 -07002073 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002074 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002075 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002076
2077 LocationAccessPolicy.LocationPermissionResult locationResult =
2078 LocationAccessPolicy.checkLocationPermission(mApp,
2079 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2080 .setCallingPackage(callingPackage)
2081 .setCallingPid(Binder.getCallingPid())
2082 .setCallingUid(Binder.getCallingUid())
2083 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002084 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002085 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2086 .build());
2087 switch (locationResult) {
2088 case DENIED_HARD:
2089 throw new SecurityException("Not allowed to access cell info");
2090 case DENIED_SOFT:
2091 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002092 }
2093
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002094 final int targetSdk = getTargetSdk(callingPackage);
2095 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2096 return getCachedCellInfo();
2097 }
2098
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002099 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002100 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08002101 final long identity = Binder.clearCallingIdentity();
2102 try {
2103 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2104 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002105 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002106 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002107 if (info != null) cellInfos.addAll(info);
2108 }
2109 return cellInfos;
2110 } finally {
2111 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002112 }
2113 }
2114
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002115 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002116 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2117 requestCellInfoUpdateInternal(
2118 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2119 }
2120
2121 @Override
2122 public void requestCellInfoUpdateWithWorkSource(
2123 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2124 enforceModifyPermission();
2125 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2126 }
2127
2128 private void requestCellInfoUpdateInternal(
2129 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002130 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002131 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002132
2133 LocationAccessPolicy.LocationPermissionResult locationResult =
2134 LocationAccessPolicy.checkLocationPermission(mApp,
2135 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2136 .setCallingPackage(callingPackage)
2137 .setCallingPid(Binder.getCallingPid())
2138 .setCallingUid(Binder.getCallingUid())
2139 .setMethod("requestCellInfoUpdate")
2140 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2141 .build());
2142 switch (locationResult) {
2143 case DENIED_HARD:
2144 throw new SecurityException("Not allowed to access cell info");
2145 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002146 try {
2147 cb.onCellInfo(new ArrayList<CellInfo>());
2148 } catch (RemoteException re) {
2149 // Drop without consequences
2150 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002151 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002152 }
2153
Nathan Harolda939a962019-05-09 10:13:47 -07002154
2155 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002156 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2157
2158 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2159 }
2160
2161 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002162 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002163 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002164 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08002165
2166 final long identity = Binder.clearCallingIdentity();
2167 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002168 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002169 } finally {
2170 Binder.restoreCallingIdentity(identity);
2171 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002172 }
2173
Shishir Agrawala9f32182016-04-12 12:00:16 -07002174 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002175 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002176 Phone phone = PhoneFactory.getPhone(slotIndex);
2177 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002178 return null;
2179 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002180 int subId = phone.getSubId();
2181 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2182 mApp, subId, callingPackage, "getImeiForSlot")) {
2183 return null;
2184 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002185
2186 final long identity = Binder.clearCallingIdentity();
2187 try {
2188 return phone.getImei();
2189 } finally {
2190 Binder.restoreCallingIdentity(identity);
2191 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002192 }
2193
2194 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002195 public String getTypeAllocationCodeForSlot(int slotIndex) {
2196 Phone phone = PhoneFactory.getPhone(slotIndex);
2197 String tac = null;
2198 if (phone != null) {
2199 String imei = phone.getImei();
2200 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2201 }
2202 return tac;
2203 }
2204
2205 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002206 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002207 Phone phone = PhoneFactory.getPhone(slotIndex);
2208 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002209 return null;
2210 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002211
Jeff Davidson913390f2018-02-23 17:11:49 -08002212 int subId = phone.getSubId();
2213 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2214 mApp, subId, callingPackage, "getMeidForSlot")) {
2215 return null;
2216 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002217
2218 final long identity = Binder.clearCallingIdentity();
2219 try {
2220 return phone.getMeid();
2221 } finally {
2222 Binder.restoreCallingIdentity(identity);
2223 }
Jack Yu2af8d712017-03-15 17:14:14 -07002224 }
2225
2226 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002227 public String getManufacturerCodeForSlot(int slotIndex) {
2228 Phone phone = PhoneFactory.getPhone(slotIndex);
2229 String manufacturerCode = null;
2230 if (phone != null) {
2231 String meid = phone.getMeid();
2232 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2233 }
2234 return manufacturerCode;
2235 }
2236
2237 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002238 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002239 Phone phone = PhoneFactory.getPhone(slotIndex);
2240 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002241 return null;
2242 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002243 int subId = phone.getSubId();
2244 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2245 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2246 return null;
2247 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002248
2249 final long identity = Binder.clearCallingIdentity();
2250 try {
2251 return phone.getDeviceSvn();
2252 } finally {
2253 Binder.restoreCallingIdentity(identity);
2254 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002255 }
2256
fionaxu43304da2017-11-27 22:51:16 -08002257 @Override
2258 public int getSubscriptionCarrierId(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002259 final long identity = Binder.clearCallingIdentity();
2260 try {
2261 final Phone phone = getPhone(subId);
2262 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2263 } finally {
2264 Binder.restoreCallingIdentity(identity);
2265 }
fionaxu43304da2017-11-27 22:51:16 -08002266 }
2267
2268 @Override
2269 public String getSubscriptionCarrierName(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002270 final long identity = Binder.clearCallingIdentity();
2271 try {
2272 final Phone phone = getPhone(subId);
2273 return phone == null ? null : phone.getCarrierName();
2274 } finally {
2275 Binder.restoreCallingIdentity(identity);
2276 }
fionaxu43304da2017-11-27 22:51:16 -08002277 }
2278
calvinpaneed9ae82018-11-01 19:43:06 +08002279 @Override
chen xua31f22b2019-03-06 15:28:50 -08002280 public int getSubscriptionSpecificCarrierId(int subId) {
chen xuc93cc282018-11-04 17:17:00 -08002281 final long identity = Binder.clearCallingIdentity();
2282 try {
2283 final Phone phone = getPhone(subId);
2284 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xua31f22b2019-03-06 15:28:50 -08002285 : phone.getSpecificCarrierId();
chen xuc93cc282018-11-04 17:17:00 -08002286 } finally {
2287 Binder.restoreCallingIdentity(identity);
2288 }
2289 }
2290
2291 @Override
chen xua31f22b2019-03-06 15:28:50 -08002292 public String getSubscriptionSpecificCarrierName(int subId) {
chen xuc93cc282018-11-04 17:17:00 -08002293 final long identity = Binder.clearCallingIdentity();
2294 try {
2295 final Phone phone = getPhone(subId);
chen xua31f22b2019-03-06 15:28:50 -08002296 return phone == null ? null : phone.getSpecificCarrierName();
chen xuc93cc282018-11-04 17:17:00 -08002297 } finally {
2298 Binder.restoreCallingIdentity(identity);
2299 }
2300 }
2301
chen xu02581692018-11-11 19:03:44 -08002302 @Override
chen xu4ca4e692018-12-06 22:10:03 -08002303 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2304 if (!isSubscriptionMccMnc) {
2305 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2306 }
chen xu02581692018-11-11 19:03:44 -08002307 final Phone phone = PhoneFactory.getPhone(slotIndex);
2308 if (phone == null) {
2309 return TelephonyManager.UNKNOWN_CARRIER_ID;
2310 }
2311 final long identity = Binder.clearCallingIdentity();
2312 try {
2313 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2314 } finally {
2315 Binder.restoreCallingIdentity(identity);
2316 }
2317 }
2318
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002319 //
2320 // Internal helper methods.
2321 //
2322
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002323 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002324 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2325 *
2326 * @throws SecurityException if the caller does not have the required permission
2327 */
2328 private void enforceModifyPermission() {
2329 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2330 }
2331
2332 /**
2333 * Make sure the caller has the CALL_PHONE permission.
2334 *
2335 * @throws SecurityException if the caller does not have the required permission
2336 */
2337 private void enforceCallPermission() {
2338 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2339 }
2340
Stuart Scott8eef64f2015-04-08 15:13:54 -07002341 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002342 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002343 "ConnectivityService");
2344 }
2345
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002346 private String createTelUrl(String number) {
2347 if (TextUtils.isEmpty(number)) {
2348 return null;
2349 }
2350
Jake Hambye994d462014-02-03 13:10:13 -08002351 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002352 }
2353
Ihab Awadf9e92732013-12-05 18:02:52 -08002354 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002355 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2356 }
2357
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002358 private static void logv(String msg) {
2359 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2360 }
2361
Ihab Awadf9e92732013-12-05 18:02:52 -08002362 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002363 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2364 }
2365
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002366 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002367 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002368 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002369 }
2370
Sanket Padawe356d7632015-06-22 14:03:32 -07002371 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002372 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002373 final long identity = Binder.clearCallingIdentity();
2374 try {
2375 final Phone phone = PhoneFactory.getPhone(slotIndex);
2376 if (phone == null) {
2377 return PhoneConstants.PHONE_TYPE_NONE;
2378 } else {
2379 return phone.getPhoneType();
2380 }
2381 } finally {
2382 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002383 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002384 }
2385
2386 /**
2387 * Returns the CDMA ERI icon index to display
2388 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002389 @Override
2390 public int getCdmaEriIconIndex(String callingPackage) {
2391 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002392 }
2393
Sanket Padawe356d7632015-06-22 14:03:32 -07002394 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002395 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002396 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002397 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002398 return -1;
2399 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002400
2401 final long identity = Binder.clearCallingIdentity();
2402 try {
2403 final Phone phone = getPhone(subId);
2404 if (phone != null) {
2405 return phone.getCdmaEriIconIndex();
2406 } else {
2407 return -1;
2408 }
2409 } finally {
2410 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002411 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002412 }
2413
2414 /**
2415 * Returns the CDMA ERI icon mode,
2416 * 0 - ON
2417 * 1 - FLASHING
2418 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002419 @Override
2420 public int getCdmaEriIconMode(String callingPackage) {
2421 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002422 }
2423
Sanket Padawe356d7632015-06-22 14:03:32 -07002424 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002425 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002426 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002427 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002428 return -1;
2429 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002430
2431 final long identity = Binder.clearCallingIdentity();
2432 try {
2433 final Phone phone = getPhone(subId);
2434 if (phone != null) {
2435 return phone.getCdmaEriIconMode();
2436 } else {
2437 return -1;
2438 }
2439 } finally {
2440 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002441 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002442 }
2443
2444 /**
2445 * Returns the CDMA ERI text,
2446 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002447 @Override
2448 public String getCdmaEriText(String callingPackage) {
2449 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002450 }
2451
Sanket Padawe356d7632015-06-22 14:03:32 -07002452 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002453 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002454 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002455 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002456 return null;
2457 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002458
2459 final long identity = Binder.clearCallingIdentity();
2460 try {
2461 final Phone phone = getPhone(subId);
2462 if (phone != null) {
2463 return phone.getCdmaEriText();
2464 } else {
2465 return null;
2466 }
2467 } finally {
2468 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002469 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002470 }
2471
2472 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002473 * Returns the CDMA MDN.
2474 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002475 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002476 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002477 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2478 mApp, subId, "getCdmaMdn");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002479
2480 final long identity = Binder.clearCallingIdentity();
2481 try {
2482 final Phone phone = getPhone(subId);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002483 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002484 return phone.getLine1Number();
2485 } else {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002486 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002487 return null;
2488 }
2489 } finally {
2490 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002491 }
2492 }
2493
2494 /**
2495 * Returns the CDMA MIN.
2496 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002497 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002498 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002499 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2500 mApp, subId, "getCdmaMin");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002501
2502 final long identity = Binder.clearCallingIdentity();
2503 try {
2504 final Phone phone = getPhone(subId);
2505 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2506 return phone.getCdmaMin();
2507 } else {
2508 return null;
2509 }
2510 } finally {
2511 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002512 }
2513 }
2514
Hall Liud892bec2018-11-30 14:51:45 -08002515 @Override
2516 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2517 INumberVerificationCallback callback, String callingPackage) {
2518 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2519 != PERMISSION_GRANTED) {
2520 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2521 }
2522 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2523
2524 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2525 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2526 throw new SecurityException("Calling package must be configured in the device config");
2527 }
2528
2529 if (range == null) {
2530 throw new NullPointerException("Range must be non-null");
2531 }
2532
2533 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002534 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002535
2536 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2537 }
2538
Junda Liuca05d5d2014-08-14 22:36:34 -07002539 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002540 * Returns true if CDMA provisioning needs to run.
2541 */
2542 public boolean needsOtaServiceProvisioning() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002543 final long identity = Binder.clearCallingIdentity();
2544 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002545 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chend965c8b2018-02-28 15:00:40 -08002546 } finally {
2547 Binder.restoreCallingIdentity(identity);
2548 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002549 }
2550
2551 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002552 * Sets the voice mail number of a given subId.
2553 */
2554 @Override
2555 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002556 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002557
2558 final long identity = Binder.clearCallingIdentity();
2559 try {
2560 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2561 new Pair<String, String>(alphaTag, number), new Integer(subId));
2562 return success;
2563 } finally {
2564 Binder.restoreCallingIdentity(identity);
2565 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002566 }
2567
Ta-wei Yen87c49842016-05-13 21:19:52 -07002568 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002569 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2570 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002571 String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002572 if (!TextUtils.equals(callingPackage, systemDialer)) {
2573 throw new SecurityException("caller must be system dialer");
2574 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002575
2576 final long identity = Binder.clearCallingIdentity();
2577 try {
2578 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2579 if (phoneAccountHandle == null) {
2580 return null;
2581 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002582 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002583 } finally {
2584 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002585 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002586 }
2587
2588 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002589 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002590 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002591 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002592 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002593 return null;
2594 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002595
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002596 final long identity = Binder.clearCallingIdentity();
2597 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002598 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002599 } finally {
2600 Binder.restoreCallingIdentity(identity);
2601 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002602 }
2603
2604 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002605 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2606 VisualVoicemailSmsFilterSettings settings) {
2607 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002608
2609 final long identity = Binder.clearCallingIdentity();
2610 try {
2611 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002612 mApp, callingPackage, subId, settings);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002613 } finally {
2614 Binder.restoreCallingIdentity(identity);
2615 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002616 }
2617
2618 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002619 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2620 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002621
2622 final long identity = Binder.clearCallingIdentity();
2623 try {
2624 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002625 mApp, callingPackage, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002626 } finally {
2627 Binder.restoreCallingIdentity(identity);
2628 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002629 }
2630
2631 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002632 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2633 String callingPackage, int subId) {
2634 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002635
2636 final long identity = Binder.clearCallingIdentity();
2637 try {
2638 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002639 mApp, callingPackage, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002640 } finally {
2641 Binder.restoreCallingIdentity(identity);
2642 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002643 }
2644
2645 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002646 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002647 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002648
2649 final long identity = Binder.clearCallingIdentity();
2650 try {
2651 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002652 mApp, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002653 } finally {
2654 Binder.restoreCallingIdentity(identity);
2655 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002656 }
2657
2658 @Override
2659 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2660 String number, int port, String text, PendingIntent sentIntent) {
2661 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002662 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002663 enforceSendSmsPermission();
Amit Mahajan716e76c2019-05-13 13:48:32 -07002664 SmsController smsController = PhoneFactory.getSmsController();
2665 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
2666 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002667 }
Amit Mahajan716e76c2019-05-13 13:48:32 -07002668
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002669 /**
fionaxu0152e512016-11-14 13:36:14 -08002670 * Sets the voice activation state of a given subId.
2671 */
2672 @Override
2673 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002674 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2675 mApp, subId, "setVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002676
2677 final long identity = Binder.clearCallingIdentity();
2678 try {
2679 final Phone phone = getPhone(subId);
2680 if (phone != null) {
2681 phone.setVoiceActivationState(activationState);
2682 } else {
2683 loge("setVoiceActivationState fails with invalid subId: " + subId);
2684 }
2685 } finally {
2686 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002687 }
2688 }
2689
2690 /**
2691 * Sets the data activation state of a given subId.
2692 */
2693 @Override
2694 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002695 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2696 mApp, subId, "setDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002697
2698 final long identity = Binder.clearCallingIdentity();
2699 try {
2700 final Phone phone = getPhone(subId);
2701 if (phone != null) {
2702 phone.setDataActivationState(activationState);
2703 } else {
2704 loge("setVoiceActivationState fails with invalid subId: " + subId);
2705 }
2706 } finally {
2707 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002708 }
2709 }
2710
2711 /**
2712 * Returns the voice activation state of a given subId.
2713 */
2714 @Override
2715 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002716 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002717
fionaxu0152e512016-11-14 13:36:14 -08002718 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002719 final long identity = Binder.clearCallingIdentity();
2720 try {
2721 if (phone != null) {
2722 return phone.getVoiceActivationState();
2723 } else {
2724 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2725 }
2726 } finally {
2727 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002728 }
2729 }
2730
2731 /**
2732 * Returns the data activation state of a given subId.
2733 */
2734 @Override
2735 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002736 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002737
fionaxu0152e512016-11-14 13:36:14 -08002738 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002739 final long identity = Binder.clearCallingIdentity();
2740 try {
2741 if (phone != null) {
2742 return phone.getDataActivationState();
2743 } else {
2744 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2745 }
2746 } finally {
2747 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002748 }
2749 }
2750
2751 /**
Wink Saville36469e72014-06-11 15:17:00 -07002752 * Returns the unread count of voicemails for a subId
2753 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002754 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002755 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2756 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2757 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2758 return 0;
2759 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002760 final long identity = Binder.clearCallingIdentity();
2761 try {
2762 final Phone phone = getPhone(subId);
2763 if (phone != null) {
2764 return phone.getVoiceMessageCount();
2765 } else {
2766 return 0;
2767 }
2768 } finally {
2769 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002770 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002771 }
2772
2773 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002774 * returns true, if the device is in a state where both voice and data
2775 * are supported simultaneously. This can change based on location or network condition.
2776 */
2777 @Override
2778 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002779 final long identity = Binder.clearCallingIdentity();
2780 try {
2781 final Phone phone = getPhone(subId);
2782 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2783 } finally {
2784 Binder.restoreCallingIdentity(identity);
2785 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002786 }
2787
2788 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002789 * Send the dialer code if called from the current default dialer or the caller has
2790 * carrier privilege.
2791 * @param inputCode The dialer code to send
2792 */
2793 @Override
2794 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002795 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002796 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002797 String defaultDialer = TelecomManager.from(defaultPhone.getContext())
2798 .getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002799 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002800 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2801 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002802 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002803
2804 final long identity = Binder.clearCallingIdentity();
2805 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002806 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002807 } finally {
2808 Binder.restoreCallingIdentity(identity);
2809 }
fionaxu235cc5e2017-03-06 22:25:57 -08002810 }
2811
Pengquan Meng0c05b502018-09-06 09:59:22 -07002812 @Override
2813 public int getNetworkSelectionMode(int subId) {
Pengquan Meng466e2482018-09-21 15:54:48 -07002814 if (!isActiveSubscription(subId)) {
2815 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2816 }
2817
Pengquan Meng0c05b502018-09-06 09:59:22 -07002818 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2819 }
2820
Brad Ebinger4c460712018-10-01 10:40:55 -07002821 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002822 public boolean isInEmergencySmsMode() {
2823 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2824 final long identity = Binder.clearCallingIdentity();
2825 try {
2826 for (Phone phone : PhoneFactory.getPhones()) {
2827 if (phone.isInEmergencySmsMode()) {
2828 return true;
2829 }
2830 }
2831 } finally {
2832 Binder.restoreCallingIdentity(identity);
2833 }
2834 return false;
2835 }
2836
2837 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002838 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2839 throws RemoteException {
2840 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002841 final long token = Binder.clearCallingIdentity();
2842 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002843 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002844 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002845 .addRegistrationCallbackForSubscription(c, subId);
2846 } finally {
2847 Binder.restoreCallingIdentity(token);
2848 }
2849 }
2850
2851 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002852 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2853 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002854 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2855 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2856 }
2857 Binder.withCleanCallingIdentity(() -> {
2858 try {
2859 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002860 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002861 .removeRegistrationCallbackForSubscription(c, subId);
2862 } catch (IllegalArgumentException e) {
2863 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2864 + "is inactive, ignoring unregister.");
2865 // If the subscription is no longer active, just return, since the callback
2866 // will already have been removed internally.
2867 }
2868 });
Brad Ebinger4c460712018-10-01 10:40:55 -07002869 }
2870
2871 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002872 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2873 throws RemoteException {
2874 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002875 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2876 final long token = Binder.clearCallingIdentity();
2877 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002878 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002879 .addCapabilitiesCallbackForSubscription(c, subId);
2880 } finally {
2881 Binder.restoreCallingIdentity(token);
2882 }
2883 }
2884
2885 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002886 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2887 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002888
2889 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2890 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2891 }
2892 Binder.withCleanCallingIdentity(() -> {
2893 try {
2894 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002895 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002896 .removeCapabilitiesCallbackForSubscription(c, subId);
2897 } catch (IllegalArgumentException e) {
2898 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
2899 + "is inactive, ignoring unregister.");
2900 // If the subscription is no longer active, just return, since the callback
2901 // will already have been removed internally.
2902 }
2903 });
Brad Ebinger4c460712018-10-01 10:40:55 -07002904 }
2905
2906 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002907 public boolean isCapable(int subId, int capability, int regTech) {
2908 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002909 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2910 final long token = Binder.clearCallingIdentity();
2911 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002912 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002913 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2914 } catch (ImsException e) {
2915 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2916 return false;
Brad Ebinger6b5ac222019-02-04 14:36:52 -08002917 } catch (IllegalArgumentException e) {
2918 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
2919 return false;
Brad Ebinger4c460712018-10-01 10:40:55 -07002920 } finally {
2921 Binder.restoreCallingIdentity(token);
2922 }
2923 }
2924
2925 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002926 public boolean isAvailable(int subId, int capability, int regTech) {
2927 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002928 final long token = Binder.clearCallingIdentity();
2929 try {
2930 Phone phone = getPhone(subId);
2931 if (phone == null) return false;
2932 return phone.isImsCapabilityAvailable(capability, regTech);
2933 } finally {
2934 Binder.restoreCallingIdentity(token);
2935 }
2936 }
2937
2938 @Override
2939 public boolean isAdvancedCallingSettingEnabled(int subId) {
2940 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2941 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2942 final long token = Binder.clearCallingIdentity();
2943 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002944 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002945 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2946 } finally {
2947 Binder.restoreCallingIdentity(token);
2948 }
2949 }
2950
2951 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08002952 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002953 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08002954 "setAdvancedCallingSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002955 final long identity = Binder.clearCallingIdentity();
2956 try {
2957 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002958 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002959 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2960 } finally {
2961 Binder.restoreCallingIdentity(identity);
2962 }
2963 }
2964
2965 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002966 public boolean isVtSettingEnabled(int subId) {
2967 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002968 final long identity = Binder.clearCallingIdentity();
2969 try {
2970 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002971 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002972 getSlotIndexOrException(subId)).isVtEnabledByUser();
2973 } finally {
2974 Binder.restoreCallingIdentity(identity);
2975 }
2976 }
2977
2978 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08002979 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002980 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08002981 "setVtSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002982 final long identity = Binder.clearCallingIdentity();
2983 try {
2984 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002985 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger4c460712018-10-01 10:40:55 -07002986 } finally {
2987 Binder.restoreCallingIdentity(identity);
2988 }
2989 }
2990
2991 @Override
2992 public boolean isVoWiFiSettingEnabled(int subId) {
2993 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
2994 final long identity = Binder.clearCallingIdentity();
2995 try {
2996 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002997 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002998 getSlotIndexOrException(subId)).isWfcEnabledByUser();
2999 } finally {
3000 Binder.restoreCallingIdentity(identity);
3001 }
3002 }
3003
3004 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08003005 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07003006 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08003007 "setVoWiFiSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07003008 final long identity = Binder.clearCallingIdentity();
3009 try {
3010 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003011 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger4c460712018-10-01 10:40:55 -07003012 } finally {
3013 Binder.restoreCallingIdentity(identity);
3014 }
3015 }
3016
3017 @Override
3018 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3019 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3020 final long identity = Binder.clearCallingIdentity();
3021 try {
3022 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003023 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003024 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
3025 } finally {
3026 Binder.restoreCallingIdentity(identity);
3027 }
3028 }
3029
3030 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08003031 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07003032 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08003033 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07003034 final long identity = Binder.clearCallingIdentity();
3035 try {
3036 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003037 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003038 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
3039 } finally {
3040 Binder.restoreCallingIdentity(identity);
3041 }
3042 }
3043
3044 @Override
3045 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3046 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3047 "setVoWiFiNonPersistent");
3048 final long identity = Binder.clearCallingIdentity();
3049 try {
3050 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003051 ImsManager.getInstance(mApp,
Brad Ebinger2bc95702019-05-07 18:33:46 -07003052 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger4c460712018-10-01 10:40:55 -07003053 } finally {
3054 Binder.restoreCallingIdentity(identity);
3055 }
3056 }
3057
3058 @Override
3059 public int getVoWiFiModeSetting(int subId) {
3060 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3061 final long identity = Binder.clearCallingIdentity();
3062 try {
3063 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003064 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003065 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
3066 } finally {
3067 Binder.restoreCallingIdentity(identity);
3068 }
3069 }
3070
3071 @Override
3072 public void setVoWiFiModeSetting(int subId, int mode) {
3073 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3074 "setVoWiFiModeSetting");
3075 final long identity = Binder.clearCallingIdentity();
3076 try {
3077 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003078 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003079 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
3080 } finally {
3081 Binder.restoreCallingIdentity(identity);
3082 }
3083 }
3084
3085 @Override
3086 public int getVoWiFiRoamingModeSetting(int subId) {
3087 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3088 final long identity = Binder.clearCallingIdentity();
3089 try {
3090 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003091 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003092 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
3093 } finally {
3094 Binder.restoreCallingIdentity(identity);
3095 }
3096 }
3097
3098 @Override
3099 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3100 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3101 "setVoWiFiRoamingModeSetting");
3102 final long identity = Binder.clearCallingIdentity();
3103 try {
3104 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003105 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003106 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
3107 } finally {
3108 Binder.restoreCallingIdentity(identity);
3109 }
3110 }
3111
3112 @Override
3113 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3114 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3115 "setRttCapabilityEnabled");
3116 final long identity = Binder.clearCallingIdentity();
3117 try {
3118 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003119 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003120 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3121 } finally {
3122 Binder.restoreCallingIdentity(identity);
3123 }
3124 }
3125
3126 @Override
3127 public boolean isTtyOverVolteEnabled(int subId) {
3128 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3129 final long identity = Binder.clearCallingIdentity();
3130 try {
3131 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003132 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003133 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
3134 } finally {
3135 Binder.restoreCallingIdentity(identity);
3136 }
3137 }
3138
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003139 @Override
3140 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3141 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3142 final long identity = Binder.clearCallingIdentity();
3143 try {
3144 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003145 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003146 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003147 } finally {
3148 Binder.restoreCallingIdentity(identity);
3149 }
3150 }
3151
3152 @Override
3153 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3154 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3155 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003156 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3157 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3158 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003159 try {
3160 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003161 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003162 .removeProvisioningCallbackForSubscription(callback, subId);
3163 } catch (IllegalArgumentException e) {
3164 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3165 + "is inactive, ignoring unregister.");
3166 // If the subscription is no longer active, just return, since the callback will already
3167 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003168 } finally {
3169 Binder.restoreCallingIdentity(identity);
3170 }
3171 }
3172
3173 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003174 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3175 boolean isProvisioned) {
3176 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3177 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3178 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3179 }
3180 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3181 "setProvisioningStatusForCapability");
3182 final long identity = Binder.clearCallingIdentity();
3183 try {
3184 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3185 Phone phone = getPhone(subId);
3186 if (phone == null) {
3187 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3188 + subId);
3189 return;
3190 }
3191 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3192 return;
3193 }
3194
3195 // this capability requires provisioning, route to the correct API.
3196 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3197 switch (capability) {
3198 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3199 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3200 ims.setVolteProvisioned(isProvisioned);
3201 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3202 ims.setWfcProvisioned(isProvisioned);
3203 }
3204 break;
3205 }
3206 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3207 // There is currently no difference in VT provisioning type.
3208 ims.setVtProvisioned(isProvisioned);
3209 break;
3210 }
3211 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3212 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3213 // change the capability of the feature instead if needed.
3214 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3215 == isProvisioned) {
3216 // No change in provisioning.
3217 return;
3218 }
3219 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3220 try {
3221 ims.changeMmTelCapability(capability, tech, isProvisioned);
3222 } catch (ImsException e) {
3223 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3224 + ", Exception" + e.getMessage());
3225 }
3226 break;
3227 }
3228 default: {
3229 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3230 + capability + "', which does not require provisioning.");
3231 }
3232 }
3233
3234 } finally {
3235 Binder.restoreCallingIdentity(identity);
3236 }
3237 }
3238
3239 @Override
3240 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3241 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3242 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3243 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3244 }
3245 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3246 final long identity = Binder.clearCallingIdentity();
3247 try {
3248 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3249 Phone phone = getPhone(subId);
3250 if (phone == null) {
3251 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3252 + subId);
3253 // We will fail with "true" as the provisioning status because this is the default
3254 // if we do not require provisioning.
3255 return true;
3256 }
3257
3258 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3259 return true;
3260 }
3261
3262 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3263 switch (capability) {
3264 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3265 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3266 return ims.isVolteProvisionedOnDevice();
3267 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3268 return ims.isWfcProvisionedOnDevice();
3269 }
3270 // This should never happen, since we are checking tech above to make sure it
3271 // is either LTE or IWLAN.
3272 throw new IllegalArgumentException("Invalid radio technology for voice "
3273 + "capability.");
3274 }
3275 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3276 // There is currently no difference in VT provisioning type.
3277 return ims.isVtProvisionedOnDevice();
3278 }
3279 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3280 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3281 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3282 }
3283 default: {
3284 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3285 + capability + "', which does not require provisioning.");
3286 }
3287 }
3288
3289 } finally {
3290 Binder.restoreCallingIdentity(identity);
3291 }
3292 }
3293
3294 @Override
3295 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3296 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3297 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3298 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3299 }
3300 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3301 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3302 return (provisionedBits & capability) > 0;
3303 }
3304
3305 @Override
3306 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3307 boolean isProvisioned) {
3308 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3309 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3310 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3311 }
3312 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3313 "setProvisioningStatusForCapability");
3314 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3315 // If the current provisioning status for capability already matches isProvisioned,
3316 // do nothing.
3317 if (((provisionedBits & capability) > 0) == isProvisioned) {
3318 return;
3319 }
3320 if (isProvisioned) {
3321 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3322 } else {
3323 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3324 }
3325 }
3326
3327 /**
3328 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3329 * technology. The bitfield should mirror the bitfield defined by
3330 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3331 */
3332 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3333 String key = getMmTelProvisioningKey(subId, tech);
3334 // Default is no capabilities are provisioned.
3335 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3336 }
3337
3338 /**
3339 * Sets the MmTel capability provisioning bitfield (defined by
3340 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3341 * technology specified.
3342 *
3343 * Note: This is a synchronous command and should not be called on UI thread.
3344 */
3345 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3346 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3347 String key = getMmTelProvisioningKey(subId, tech);
3348 editor.putInt(key, newField);
3349 editor.commit();
3350 }
3351
3352 private static String getMmTelProvisioningKey(int subId, int tech) {
3353 // resulting key is provision_ims_mmtel_{subId}_{tech}
3354 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3355 }
3356
3357 /**
3358 * Query CarrierConfig to see if the specified capability requires provisioning for the
3359 * carrier associated with the subscription id.
3360 */
3361 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3362 int capability) {
3363 CarrierConfigManager configManager = new CarrierConfigManager(context);
3364 PersistableBundle c = configManager.getConfigForSubId(subId);
3365 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07003366 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003367 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3368 false);
3369 boolean requireVoiceVtProvisioning = c.getBoolean(
3370 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3371
3372 // First check to make sure that the capability requires provisioning.
3373 switch (capability) {
3374 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3375 // intentional fallthrough
3376 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3377 if (requireVoiceVtProvisioning) {
3378 // Voice and Video requires provisioning
3379 return true;
3380 }
3381 break;
3382 }
3383 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3384 if (requireUtProvisioning) {
3385 // UT requires provisioning
3386 return true;
3387 }
3388 break;
3389 }
3390 }
3391 return false;
3392 }
3393
3394 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003395 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003396 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3397 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3398 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003399 enforceReadPrivilegedPermission("getImsProvisioningInt");
3400 final long identity = Binder.clearCallingIdentity();
3401 try {
3402 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003403 int slotId = getSlotIndex(subId);
3404 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3405 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3406 + subId + "' for key:" + key);
3407 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3408 }
3409 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003410 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003411 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3412 + subId + "' for key:" + key);
3413 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003414 } finally {
3415 Binder.restoreCallingIdentity(identity);
3416 }
3417 }
3418
3419 @Override
3420 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003421 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3422 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3423 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003424 enforceReadPrivilegedPermission("getImsProvisioningString");
3425 final long identity = Binder.clearCallingIdentity();
3426 try {
3427 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003428 int slotId = getSlotIndex(subId);
3429 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3430 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3431 + subId + "' for key:" + key);
3432 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3433 }
3434 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003435 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003436 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3437 + subId + "' for key:" + key);
3438 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003439 } finally {
3440 Binder.restoreCallingIdentity(identity);
3441 }
3442 }
3443
3444 @Override
3445 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003446 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3447 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3448 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003449 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3450 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003451 final long identity = Binder.clearCallingIdentity();
3452 try {
3453 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003454 int slotId = getSlotIndex(subId);
3455 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3456 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3457 + subId + "' for key:" + key);
3458 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3459 }
3460 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003461 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003462 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3463 + "' for key:" + key);
3464 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003465 } finally {
3466 Binder.restoreCallingIdentity(identity);
3467 }
3468 }
3469
3470 @Override
3471 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003472 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3473 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3474 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003475 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3476 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003477 final long identity = Binder.clearCallingIdentity();
3478 try {
3479 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003480 int slotId = getSlotIndex(subId);
3481 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3482 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3483 + subId + "' for key:" + key);
3484 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3485 }
3486 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003487 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003488 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3489 + "' for key:" + key);
3490 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003491 } finally {
3492 Binder.restoreCallingIdentity(identity);
3493 }
3494 }
3495
Brad Ebinger4c460712018-10-01 10:40:55 -07003496 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
3497 int slotId = SubscriptionManager.getSlotIndex(subId);
3498 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003499 throw new IllegalArgumentException("Invalid Subscription Id, subId=" + subId);
Brad Ebinger4c460712018-10-01 10:40:55 -07003500 }
3501 return slotId;
3502 }
3503
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003504 private int getSlotIndex(int subId) {
3505 int slotId = SubscriptionManager.getSlotIndex(subId);
3506 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3507 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3508 }
3509 return slotId;
3510 }
3511
Wink Saville36469e72014-06-11 15:17:00 -07003512 /**
Nathan Haroldb3a3a802019-05-21 15:51:27 -07003513 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07003514 */
3515 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003516 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07003517 final int targetSdk = getTargetSdk(callingPackage);
3518 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
3519 return getDataNetworkTypeForSubscriber(subId, callingPackage);
3520 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Haroldb3a3a802019-05-21 15:51:27 -07003521 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
3522 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003523 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3524 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003525
Malcolm Chend965c8b2018-02-28 15:00:40 -08003526 final long identity = Binder.clearCallingIdentity();
3527 try {
3528 final Phone phone = getPhone(subId);
3529 if (phone != null) {
3530 return phone.getServiceState().getDataNetworkType();
3531 } else {
3532 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3533 }
3534 } finally {
3535 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003536 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003537 }
3538
3539 /**
3540 * Returns the data network type
3541 */
3542 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003543 public int getDataNetworkType(String callingPackage) {
3544 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003545 }
3546
3547 /**
3548 * Returns the data network type for a subId
3549 */
3550 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003551 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003552 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003553 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003554 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3555 }
3556
Malcolm Chend965c8b2018-02-28 15:00:40 -08003557 final long identity = Binder.clearCallingIdentity();
3558 try {
3559 final Phone phone = getPhone(subId);
3560 if (phone != null) {
3561 return phone.getServiceState().getDataNetworkType();
3562 } else {
3563 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3564 }
3565 } finally {
3566 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003567 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003568 }
3569
3570 /**
Wink Saville36469e72014-06-11 15:17:00 -07003571 * Returns the Voice network type for a subId
3572 */
3573 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003574 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003575 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003576 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003577 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3578 }
3579
Malcolm Chend965c8b2018-02-28 15:00:40 -08003580 final long identity = Binder.clearCallingIdentity();
3581 try {
3582 final Phone phone = getPhone(subId);
3583 if (phone != null) {
3584 return phone.getServiceState().getVoiceNetworkType();
3585 } else {
3586 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3587 }
3588 } finally {
3589 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003590 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003591 }
3592
3593 /**
3594 * @return true if a ICC card is present
3595 */
3596 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003597 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003598 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3599 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003600 }
3601
3602 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003603 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003604 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003605 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003606 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003607 final long identity = Binder.clearCallingIdentity();
3608 try {
3609 final Phone phone = PhoneFactory.getPhone(slotIndex);
3610 if (phone != null) {
3611 return phone.getIccCard().hasIccCard();
3612 } else {
3613 return false;
3614 }
3615 } finally {
3616 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003617 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003618 }
3619
3620 /**
3621 * Return if the current radio is LTE on CDMA. This
3622 * is a tri-state return value as for a period of time
3623 * the mode may be unknown.
3624 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003625 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003626 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003627 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003628 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003629 @Override
3630 public int getLteOnCdmaMode(String callingPackage) {
3631 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003632 }
3633
Sanket Padawe356d7632015-06-22 14:03:32 -07003634 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003635 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003636 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003637 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003638 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3639 }
3640
Malcolm Chend965c8b2018-02-28 15:00:40 -08003641 final long identity = Binder.clearCallingIdentity();
3642 try {
3643 final Phone phone = getPhone(subId);
3644 if (phone == null) {
3645 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3646 } else {
3647 return phone.getLteOnCdmaMode();
3648 }
3649 } finally {
3650 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003651 }
Wink Saville36469e72014-06-11 15:17:00 -07003652 }
3653
Wink Saville36469e72014-06-11 15:17:00 -07003654 /**
3655 * {@hide}
3656 * Returns Default subId, 0 in the case of single standby.
3657 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003658 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003659 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003660 }
3661
Shishir Agrawala9f32182016-04-12 12:00:16 -07003662 private int getSlotForDefaultSubscription() {
3663 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3664 }
3665
Wink Savilleb564aae2014-10-23 10:18:09 -07003666 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003667 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003668 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003669
Pengquan Meng466e2482018-09-21 15:54:48 -07003670 private boolean isActiveSubscription(int subId) {
3671 return mSubscriptionController.isActiveSubId(subId);
3672 }
3673
Ihab Awadf2177b72013-11-25 13:33:23 -08003674 /**
3675 * @see android.telephony.TelephonyManager.WifiCallingChoices
3676 */
3677 public int getWhenToMakeWifiCalls() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003678 final long identity = Binder.clearCallingIdentity();
3679 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003680 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003681 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3682 getWhenToMakeWifiCallsDefaultPreference());
3683 } finally {
3684 Binder.restoreCallingIdentity(identity);
3685 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003686 }
3687
3688 /**
3689 * @see android.telephony.TelephonyManager.WifiCallingChoices
3690 */
3691 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003692 final long identity = Binder.clearCallingIdentity();
3693 try {
3694 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003695 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003696 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3697 } finally {
3698 Binder.restoreCallingIdentity(identity);
3699 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003700 }
3701
Sailesh Nepald1e68152013-12-12 19:08:02 -08003702 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003703 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003704 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003705 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003706
Jordan Liu73b078d2019-02-28 12:03:40 -08003707 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
3708 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
3709 if (phoneId == -1) {
3710 throw new IllegalArgumentException("Given slot index: " + slotIndex
3711 + " does not correspond to an active phone");
3712 }
3713 return PhoneFactory.getPhone(phoneId);
3714 }
3715
Shishir Agrawal566b7612013-10-28 14:41:00 -07003716 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003717 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3718 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003719 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3720 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003721 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu73b078d2019-02-28 12:03:40 -08003722 if (DBG) {
3723 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3724 }
3725 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
3726 p2);
3727 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003728
Jordan Liu73b078d2019-02-28 12:03:40 -08003729
3730 @Override
3731 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
3732 int slotIndex, String callingPackage, String aid, int p2) {
3733 enforceModifyPermission();
3734 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3735 if (DBG) {
3736 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
3737 }
3738 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3739 callingPackage, aid, p2);
3740 }
3741
3742 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
3743 String callingPackage, String aid, int p2) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003744 final long identity = Binder.clearCallingIdentity();
3745 try {
3746 if (TextUtils.equals(ISDR_AID, aid)) {
3747 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003748 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3749 .getContext().getPackageManager());
Malcolm Chend965c8b2018-02-28 15:00:40 -08003750 if (bestComponent == null
3751 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3752 loge("The calling package is not allowed to access ISD-R.");
3753 throw new SecurityException(
3754 "The calling package is not allowed to access ISD-R.");
3755 }
Derek Tan740e1672017-06-27 14:56:27 -07003756 }
Derek Tan740e1672017-06-27 14:56:27 -07003757
Malcolm Chend965c8b2018-02-28 15:00:40 -08003758 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu73b078d2019-02-28 12:03:40 -08003759 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
3760 null /* workSource */);
3761 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003762 return response;
3763 } finally {
3764 Binder.restoreCallingIdentity(identity);
3765 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003766 }
3767
3768 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003769 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003770 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3771 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu73b078d2019-02-28 12:03:40 -08003772 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3773 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
3774 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003775
Jordan Liu73b078d2019-02-28 12:03:40 -08003776 @Override
3777 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
3778 enforceModifyPermission();
3779 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
3780 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3781 channel);
3782 }
3783
3784 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003785 final long identity = Binder.clearCallingIdentity();
3786 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003787 if (channel < 0) {
3788 return false;
3789 }
Jordan Liu73b078d2019-02-28 12:03:40 -08003790 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
3791 null /* workSource */);
3792 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003793 return success;
3794 } finally {
3795 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003796 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003797 }
3798
3799 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003800 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003801 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003802 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3803 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu73b078d2019-02-28 12:03:40 -08003804 if (DBG) {
3805 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3806 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3807 + p3 + " data=" + data);
3808 }
3809 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
3810 command, p1, p2, p3, data);
3811 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003812
Jordan Liu73b078d2019-02-28 12:03:40 -08003813 @Override
3814 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
3815 int command, int p1, int p2, int p3, String data) {
3816 enforceModifyPermission();
3817 if (DBG) {
3818 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
3819 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3820 + p3 + " data=" + data);
3821 }
3822 return iccTransmitApduLogicalChannelWithPermission(
3823 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
3824 data);
3825 }
3826
3827 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
3828 int command, int p1, int p2, int p3, String data) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003829 final long identity = Binder.clearCallingIdentity();
3830 try {
Hall Liucdcfa292019-05-02 09:16:29 -07003831 if (channel <= 0) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003832 return "";
3833 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003834
Malcolm Chend965c8b2018-02-28 15:00:40 -08003835 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu73b078d2019-02-28 12:03:40 -08003836 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
3837 null /* workSource */);
3838 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003839
Malcolm Chend965c8b2018-02-28 15:00:40 -08003840 // Append the returned status code to the end of the response payload.
3841 String s = Integer.toHexString(
3842 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3843 if (response.payload != null) {
3844 s = IccUtils.bytesToHexString(response.payload) + s;
3845 }
3846 return s;
3847 } finally {
3848 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003849 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003850 }
Jake Hambye994d462014-02-03 13:10:13 -08003851
Evan Charltonc66da362014-05-16 14:06:40 -07003852 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003853 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3854 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003855 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3856 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003857 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu73b078d2019-02-28 12:03:40 -08003858 if (DBG) {
3859 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3860 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3861 }
3862 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
3863 cla, command, p1, p2, p3, data);
3864 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003865
Jordan Liu73b078d2019-02-28 12:03:40 -08003866 @Override
3867 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
3868 int command, int p1, int p2, int p3, String data) {
3869 enforceModifyPermission();
3870 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3871 if (DBG) {
3872 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
3873 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
3874 + " data=" + data);
3875 }
3876
3877 return iccTransmitApduBasicChannelWithPermission(
3878 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
3879 p2, p3, data);
3880 }
3881
3882 // open APDU basic channel assuming the caller has sufficient permissions
3883 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
3884 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003885 final long identity = Binder.clearCallingIdentity();
3886 try {
3887 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3888 && TextUtils.equals(ISDR_AID, data)) {
3889 // Only allows LPA to select ISD-R.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003890 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3891 .getContext().getPackageManager());
Malcolm Chend965c8b2018-02-28 15:00:40 -08003892 if (bestComponent == null
3893 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3894 loge("The calling package is not allowed to select ISD-R.");
3895 throw new SecurityException(
3896 "The calling package is not allowed to select ISD-R.");
3897 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003898 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003899
Malcolm Chend965c8b2018-02-28 15:00:40 -08003900 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu73b078d2019-02-28 12:03:40 -08003901 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
3902 null /* workSource */);
3903 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003904
Malcolm Chend965c8b2018-02-28 15:00:40 -08003905 // Append the returned status code to the end of the response payload.
3906 String s = Integer.toHexString(
3907 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3908 if (response.payload != null) {
3909 s = IccUtils.bytesToHexString(response.payload) + s;
3910 }
3911 return s;
3912 } finally {
3913 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003914 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003915 }
3916
3917 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003918 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003919 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003920 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3921 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003922
Malcolm Chend965c8b2018-02-28 15:00:40 -08003923 final long identity = Binder.clearCallingIdentity();
3924 try {
3925 if (DBG) {
3926 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3927 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3928 }
3929
3930 IccIoResult response =
3931 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3932 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3933 subId);
3934
3935 if (DBG) {
3936 log("Exchange SIM_IO [R]" + response);
3937 }
3938
3939 byte[] result = null;
3940 int length = 2;
3941 if (response.payload != null) {
3942 length = 2 + response.payload.length;
3943 result = new byte[length];
3944 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3945 } else {
3946 result = new byte[length];
3947 }
3948
3949 result[length - 1] = (byte) response.sw2;
3950 result[length - 2] = (byte) response.sw1;
3951 return result;
3952 } finally {
3953 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003954 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003955 }
3956
Nathan Haroldb3014052017-01-25 15:57:32 -08003957 /**
3958 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3959 * on a particular subscription
3960 */
sqianb6e41952018-03-12 14:54:01 -07003961 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3962 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3963 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3964 return null;
3965 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003966
3967 final long identity = Binder.clearCallingIdentity();
3968 try {
3969 if (appType != TelephonyManager.APPTYPE_USIM
3970 && appType != TelephonyManager.APPTYPE_SIM) {
3971 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3972 return null;
3973 }
3974 Object response = sendRequest(
3975 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3976 if (response instanceof String[]) {
3977 return (String[]) response;
3978 }
3979 // Response is an Exception of some kind,
3980 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003981 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08003982 } finally {
3983 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003984 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003985 }
3986
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003987 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003988 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003989 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3990 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003991
Malcolm Chend965c8b2018-02-28 15:00:40 -08003992 final long identity = Binder.clearCallingIdentity();
3993 try {
3994 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3995 if (response.payload == null) {
3996 return "";
3997 }
Evan Charltonc66da362014-05-16 14:06:40 -07003998
Malcolm Chend965c8b2018-02-28 15:00:40 -08003999 // Append the returned status code to the end of the response payload.
4000 String s = Integer.toHexString(
4001 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4002 s = IccUtils.bytesToHexString(response.payload) + s;
4003 return s;
4004 } finally {
4005 Binder.restoreCallingIdentity(identity);
4006 }
Evan Charltonc66da362014-05-16 14:06:40 -07004007 }
4008
Jake Hambye994d462014-02-03 13:10:13 -08004009 /**
4010 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4011 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4012 *
4013 * @param itemID the ID of the item to read
4014 * @return the NV item as a String, or null on error.
4015 */
4016 @Override
4017 public String nvReadItem(int itemID) {
vagdevie435a3e2018-08-15 16:01:53 -07004018 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004019 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4020 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004021
4022 final long identity = Binder.clearCallingIdentity();
4023 try {
4024 if (DBG) log("nvReadItem: item " + itemID);
vagdevie435a3e2018-08-15 16:01:53 -07004025 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004026 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4027 return value;
4028 } finally {
4029 Binder.restoreCallingIdentity(identity);
4030 }
Jake Hambye994d462014-02-03 13:10:13 -08004031 }
4032
4033 /**
4034 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4035 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4036 *
4037 * @param itemID the ID of the item to read
4038 * @param itemValue the value to write, as a String
4039 * @return true on success; false on any failure
4040 */
4041 @Override
4042 public boolean nvWriteItem(int itemID, String itemValue) {
vagdevie435a3e2018-08-15 16:01:53 -07004043 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004044 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4045 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004046
4047 final long identity = Binder.clearCallingIdentity();
4048 try {
4049 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4050 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdevie435a3e2018-08-15 16:01:53 -07004051 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004052 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4053 return success;
4054 } finally {
4055 Binder.restoreCallingIdentity(identity);
4056 }
Jake Hambye994d462014-02-03 13:10:13 -08004057 }
4058
4059 /**
4060 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4061 * Used for device configuration by some CDMA operators.
4062 *
4063 * @param preferredRoamingList byte array containing the new PRL
4064 * @return true on success; false on any failure
4065 */
4066 @Override
4067 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004068 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4069 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004070
4071 final long identity = Binder.clearCallingIdentity();
4072 try {
4073 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4074 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4075 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4076 return success;
4077 } finally {
4078 Binder.restoreCallingIdentity(identity);
4079 }
Jake Hambye994d462014-02-03 13:10:13 -08004080 }
4081
4082 /**
chen xu1cc0abe2018-10-26 17:39:23 -07004083 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004084 * Used for device configuration by some CDMA operators.
4085 *
chen xu1cc0abe2018-10-26 17:39:23 -07004086 * @param slotIndex - device slot.
4087 *
Jake Hambye994d462014-02-03 13:10:13 -08004088 * @return true on success; false on any failure
4089 */
4090 @Override
chen xu1cc0abe2018-10-26 17:39:23 -07004091 public boolean resetModemConfig(int slotIndex) {
4092 Phone phone = PhoneFactory.getPhone(slotIndex);
4093 if (phone != null) {
4094 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4095 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004096
chen xu1cc0abe2018-10-26 17:39:23 -07004097 final long identity = Binder.clearCallingIdentity();
4098 try {
4099 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4100 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4101 return success;
4102 } finally {
4103 Binder.restoreCallingIdentity(identity);
4104 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004105 }
chen xu1cc0abe2018-10-26 17:39:23 -07004106 return false;
4107 }
4108
4109 /**
4110 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4111 *
4112 * @param slotIndex - device slot.
4113 *
4114 * @return true on success; false on any failure
4115 */
4116 @Override
4117 public boolean rebootModem(int slotIndex) {
4118 Phone phone = PhoneFactory.getPhone(slotIndex);
4119 if (phone != null) {
4120 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4121 mApp, phone.getSubId(), "rebootModem");
4122
4123 final long identity = Binder.clearCallingIdentity();
4124 try {
4125 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4126 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4127 return success;
4128 } finally {
4129 Binder.restoreCallingIdentity(identity);
4130 }
4131 }
4132 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004133 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004134
Svet Ganovb320e182015-04-16 12:30:10 -07004135 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004136 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004137 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004138 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004139 return new String[0];
4140 }
4141
Malcolm Chend965c8b2018-02-28 15:00:40 -08004142 final long identity = Binder.clearCallingIdentity();
4143 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004144 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004145 } finally {
4146 Binder.restoreCallingIdentity(identity);
4147 }
Wink Saville36469e72014-06-11 15:17:00 -07004148 }
4149
Brad Ebinger51f743a2017-01-23 13:50:20 -08004150 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004151 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4152 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004153 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004154 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004155 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004156
4157 final long identity = Binder.clearCallingIdentity();
4158 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004159 ImsResolver resolver = PhoneFactory.getImsResolver();
4160 if (resolver == null) {
4161 // may happen if the device does not support IMS.
4162 return;
4163 }
4164 resolver.enableIms(slotId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004165 } finally {
4166 Binder.restoreCallingIdentity(identity);
4167 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004168 }
4169
4170 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004171 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4172 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004173 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004174 public void disableIms(int slotId) {
4175 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004176
4177 final long identity = Binder.clearCallingIdentity();
4178 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004179 ImsResolver resolver = PhoneFactory.getImsResolver();
4180 if (resolver == null) {
4181 // may happen if the device does not support IMS.
4182 return;
4183 }
4184 resolver.disableIms(slotId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004185 } finally {
4186 Binder.restoreCallingIdentity(identity);
4187 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004188 }
4189
4190 /**
4191 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4192 * feature or {@link null} if the service is not available. If the feature is available, the
4193 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4194 */
4195 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004196 IImsServiceFeatureCallback callback) {
4197 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004198
4199 final long identity = Binder.clearCallingIdentity();
4200 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004201 ImsResolver resolver = PhoneFactory.getImsResolver();
4202 if (resolver == null) {
4203 // may happen if the device does not support IMS.
4204 return null;
4205 }
4206 return resolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004207 } finally {
4208 Binder.restoreCallingIdentity(identity);
4209 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004210 }
4211
4212 /**
4213 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4214 * feature during emergency calling or {@link null} if the service is not available. If the
4215 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4216 * listener for feature updates.
4217 */
4218 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4219 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004220
4221 final long identity = Binder.clearCallingIdentity();
4222 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004223 ImsResolver resolver = PhoneFactory.getImsResolver();
4224 if (resolver == null) {
4225 // may happen if the device does not support IMS.
4226 return null;
4227 }
4228 return resolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004229 } finally {
4230 Binder.restoreCallingIdentity(identity);
4231 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004232 }
4233
Brad Ebinger5f64b052017-12-14 14:26:15 -08004234 /**
4235 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebingereb160e22019-01-23 15:06:19 -08004236 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004237 */
4238 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4239 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004240
4241 final long identity = Binder.clearCallingIdentity();
4242 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004243 ImsResolver resolver = PhoneFactory.getImsResolver();
4244 if (resolver == null) {
4245 // may happen if the device does not support IMS.
4246 return null;
4247 }
4248 return resolver.getImsRegistration(slotId, feature);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004249 } finally {
4250 Binder.restoreCallingIdentity(identity);
4251 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004252 }
4253
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004254 /**
4255 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebingereb160e22019-01-23 15:06:19 -08004256 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004257 */
4258 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4259 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004260
4261 final long identity = Binder.clearCallingIdentity();
4262 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004263 ImsResolver resolver = PhoneFactory.getImsResolver();
4264 if (resolver == null) {
4265 // may happen if the device does not support IMS.
4266 return null;
4267 }
4268 return resolver.getImsConfig(slotId, feature);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004269 } finally {
4270 Binder.restoreCallingIdentity(identity);
4271 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004272 }
4273
Brad Ebinger884c07b2018-02-15 16:17:40 -08004274 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004275 * Sets the ImsService Package Name that Telephony will bind to.
4276 *
4277 * @param slotId the slot ID that the ImsService should bind for.
4278 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4279 * ImsService is the device default ImsService.
4280 * @param packageName The package name of the application that contains the ImsService to bind
4281 * to.
4282 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4283 * @hide
4284 */
4285 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004286 int[] subIds = SubscriptionManager.getSubId(slotId);
4287 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4288 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4289 "setImsService");
4290
Malcolm Chend965c8b2018-02-28 15:00:40 -08004291 final long identity = Binder.clearCallingIdentity();
4292 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004293 ImsResolver resolver = PhoneFactory.getImsResolver();
4294 if (resolver == null) {
4295 // may happen if the device does not support IMS.
4296 return false;
4297 }
4298 return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService,
4299 packageName);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004300 } finally {
4301 Binder.restoreCallingIdentity(identity);
4302 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004303 }
4304
4305 /**
4306 * Return the ImsService configuration.
4307 *
4308 * @param slotId The slot that the ImsService is associated with.
4309 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4310 * the device default.
4311 * @return the package name of the ImsService configuration.
4312 */
4313 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004314 int[] subIds = SubscriptionManager.getSubId(slotId);
4315 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4316 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4317 "getImsService");
4318
Malcolm Chend965c8b2018-02-28 15:00:40 -08004319 final long identity = Binder.clearCallingIdentity();
4320 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004321 ImsResolver resolver = PhoneFactory.getImsResolver();
4322 if (resolver == null) {
4323 // may happen if the device does not support IMS.
4324 return "";
4325 }
4326 return resolver.getImsServiceConfiguration(slotId, isCarrierImsService);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004327 } finally {
4328 Binder.restoreCallingIdentity(identity);
4329 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004330 }
4331
Wink Saville36469e72014-06-11 15:17:00 -07004332 public void setImsRegistrationState(boolean registered) {
4333 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004334
4335 final long identity = Binder.clearCallingIdentity();
4336 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004337 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004338 } finally {
4339 Binder.restoreCallingIdentity(identity);
4340 }
Wink Saville36469e72014-06-11 15:17:00 -07004341 }
4342
4343 /**
Stuart Scott54788802015-03-30 13:18:01 -07004344 * Set the network selection mode to automatic.
4345 *
4346 */
4347 @Override
4348 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004349 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4350 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004351
Pengquan Meng466e2482018-09-21 15:54:48 -07004352 if (!isActiveSubscription(subId)) {
4353 return;
4354 }
4355
Malcolm Chend965c8b2018-02-28 15:00:40 -08004356 final long identity = Binder.clearCallingIdentity();
4357 try {
4358 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4359 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4360 } finally {
4361 Binder.restoreCallingIdentity(identity);
4362 }
Stuart Scott54788802015-03-30 13:18:01 -07004363 }
4364
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004365 /**
4366 * Ask the radio to connect to the input network and change selection mode to manual.
4367 *
4368 * @param subId the id of the subscription.
4369 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4370 * the operator to attach to.
4371 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4372 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4373 * normal network selection next time.
4374 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004375 */
4376 @Override
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004377 public boolean setNetworkSelectionModeManual(
4378 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004379 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4380 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Meng466e2482018-09-21 15:54:48 -07004381
4382 if (!isActiveSubscription(subId)) {
4383 return false;
4384 }
4385
Malcolm Chend965c8b2018-02-28 15:00:40 -08004386 final long identity = Binder.clearCallingIdentity();
4387 try {
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004388 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chend965c8b2018-02-28 15:00:40 -08004389 persistSelection);
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004390 if (DBG) {
4391 log("setNetworkSelectionModeManual: subId: " + subId
4392 + " operator: " + operatorInfo);
4393 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004394 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4395 } finally {
4396 Binder.restoreCallingIdentity(identity);
4397 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004398 }
4399
4400 /**
4401 * Scans for available networks.
4402 */
4403 @Override
Hall Liuf19c44f2018-11-27 14:38:17 -08004404 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004405 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4406 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004407 LocationAccessPolicy.LocationPermissionResult locationResult =
4408 LocationAccessPolicy.checkLocationPermission(mApp,
4409 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4410 .setCallingPackage(callingPackage)
4411 .setCallingPid(Binder.getCallingPid())
4412 .setCallingUid(Binder.getCallingUid())
4413 .setMethod("getCellNetworkScanResults")
4414 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4415 .build());
4416 switch (locationResult) {
4417 case DENIED_HARD:
4418 throw new SecurityException("Not allowed to access scan results -- location");
4419 case DENIED_SOFT:
4420 return null;
4421 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004422
Pengquan Meng0c05b502018-09-06 09:59:22 -07004423 long identity = Binder.clearCallingIdentity();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004424 try {
4425 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Meng0c05b502018-09-06 09:59:22 -07004426 return (CellNetworkScanResult) sendRequest(
Malcolm Chend965c8b2018-02-28 15:00:40 -08004427 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004428 } finally {
4429 Binder.restoreCallingIdentity(identity);
4430 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004431 }
4432
4433 /**
yinxub1bed742017-04-17 11:45:04 -07004434 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004435 *
yinxub1bed742017-04-17 11:45:04 -07004436 * @param subId id of the subscription
4437 * @param request contains the radio access networks with bands/channels to scan
4438 * @param messenger callback messenger for scan results or errors
4439 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004440 * @return the id of the requested scan which can be used to stop the scan.
4441 */
4442 @Override
4443 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Hall Liuf19c44f2018-11-27 14:38:17 -08004444 IBinder binder, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004445 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4446 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004447 LocationAccessPolicy.LocationPermissionResult locationResult =
4448 LocationAccessPolicy.checkLocationPermission(mApp,
4449 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4450 .setCallingPackage(callingPackage)
4451 .setCallingPid(Binder.getCallingPid())
4452 .setCallingUid(Binder.getCallingUid())
4453 .setMethod("requestNetworkScan")
4454 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4455 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004456 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
4457 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request);
4458 if (e != null) {
4459 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4460 throw e;
4461 } else {
Hall Liu46dd96a2019-04-03 12:50:44 -07004462 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004463 return TelephonyScanManager.INVALID_SCAN_ID;
4464 }
4465 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004466 }
Hall Liubac7d482019-04-25 14:02:26 -07004467 int callingUid = Binder.getCallingUid();
4468 int callingPid = Binder.getCallingPid();
yinxu612a8192019-04-18 10:38:27 -07004469 final long identity = Binder.clearCallingIdentity();
4470 try {
4471 return mNetworkScanRequestTracker.startNetworkScan(
4472 request, messenger, binder, getPhone(subId),
Hall Liubac7d482019-04-25 14:02:26 -07004473 callingUid, callingPid, callingPackage);
yinxu612a8192019-04-18 10:38:27 -07004474 } finally {
4475 Binder.restoreCallingIdentity(identity);
4476 }
yinxu504e1392017-04-12 16:03:22 -07004477 }
4478
Hall Liub2ac8ef2019-02-28 15:56:23 -08004479 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
4480 NetworkScanRequest request) {
4481 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4482 != PERMISSION_GRANTED) {
4483 return new SecurityException("permission.NETWORK_SCAN is needed for network scans"
4484 + " without location access.");
4485 }
4486
4487 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4488 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004489 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4490 return new SecurityException("Specific channels must not be"
4491 + " scanned without location access.");
4492 }
4493 }
4494 }
4495
Hall Liub2ac8ef2019-02-28 15:56:23 -08004496 return null;
4497 }
4498
yinxu504e1392017-04-12 16:03:22 -07004499 /**
4500 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004501 *
4502 * @param subId id of the subscription
4503 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004504 */
4505 @Override
4506 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004507 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4508 mApp, subId, "stopNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004509
Hall Liubac7d482019-04-25 14:02:26 -07004510 int callingUid = Binder.getCallingUid();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004511 final long identity = Binder.clearCallingIdentity();
4512 try {
Hall Liubac7d482019-04-25 14:02:26 -07004513 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004514 } finally {
4515 Binder.restoreCallingIdentity(identity);
4516 }
yinxu504e1392017-04-12 16:03:22 -07004517 }
4518
4519 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004520 * Get the calculated preferred network type.
4521 * Used for debugging incorrect network type.
4522 *
4523 * @return the preferred network type, defined in RILConstants.java.
4524 */
4525 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004526 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004527 final Phone defaultPhone = getDefaultPhone();
4528 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4529 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004530 return RILConstants.PREFERRED_NETWORK_MODE;
4531 }
4532
Malcolm Chend965c8b2018-02-28 15:00:40 -08004533 final long identity = Binder.clearCallingIdentity();
4534 try {
4535 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004536 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004537 } finally {
4538 Binder.restoreCallingIdentity(identity);
4539 }
Junda Liu84d15a22014-07-02 11:21:04 -07004540 }
4541
4542 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004543 * Get the preferred network type.
4544 * Used for device configuration by some CDMA operators.
4545 *
4546 * @return the preferred network type, defined in RILConstants.java.
4547 */
4548 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004549 public int getPreferredNetworkType(int subId) {
Pengquan Meng4848cd02018-12-20 11:00:24 -08004550 TelephonyPermissions
4551 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4552 mApp, subId, "getPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004553
4554 final long identity = Binder.clearCallingIdentity();
4555 try {
4556 if (DBG) log("getPreferredNetworkType");
4557 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4558 int networkType = (result != null ? result[0] : -1);
4559 if (DBG) log("getPreferredNetworkType: " + networkType);
4560 return networkType;
4561 } finally {
4562 Binder.restoreCallingIdentity(identity);
4563 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004564 }
4565
4566 /**
4567 * Set the preferred network type.
4568 * Used for device configuration by some CDMA operators.
4569 *
4570 * @param networkType the preferred network type, defined in RILConstants.java.
4571 * @return true on success; false on any failure.
4572 */
4573 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004574 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004575 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4576 mApp, subId, "setPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004577
4578 final long identity = Binder.clearCallingIdentity();
4579 try {
4580 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4581 Boolean success = (Boolean) sendRequest(
4582 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4583 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4584 if (success) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004585 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08004586 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4587 }
4588 return success;
4589 } finally {
4590 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004591 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004592 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004593
4594 /**
Miaoa84611c2019-03-15 09:21:10 +08004595 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004596 *
Miaoa84611c2019-03-15 09:21:10 +08004597 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004598 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004599 * @hide
4600 */
4601 @Override
Miaoa84611c2019-03-15 09:21:10 +08004602 public boolean getTetherApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004603 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004604 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08004605 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004606 try {
Miaoa84611c2019-03-15 09:21:10 +08004607 if (phone != null) {
4608 return phone.hasMatchedTetherApnSetting();
4609 } else {
4610 return false;
4611 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004612 } finally {
4613 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004614 }
Junda Liu475951f2014-11-07 16:45:03 -08004615 }
4616
4617 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004618 * Set mobile data enabled
4619 * Used by the user through settings etc to turn on/off mobile data
4620 *
4621 * @param enable {@code true} turn turn data on, else {@code false}
4622 */
4623 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004624 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004625 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4626 mApp, subId, "setUserDataEnabled");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004627
4628 final long identity = Binder.clearCallingIdentity();
4629 try {
4630 int phoneId = mSubscriptionController.getPhoneId(subId);
4631 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4632 Phone phone = PhoneFactory.getPhone(phoneId);
4633 if (phone != null) {
4634 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yu7a030e52018-12-13 11:51:28 -08004635 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004636 } else {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004637 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004638 }
4639 } finally {
4640 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004641 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004642 }
4643
4644 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004645 * Get the user enabled state of Mobile Data.
4646 *
4647 * TODO: remove and use isUserDataEnabled.
4648 * This can't be removed now because some vendor codes
4649 * calls through ITelephony directly while they should
4650 * use TelephonyManager.
4651 *
4652 * @return true on enabled
4653 */
4654 @Override
4655 public boolean getDataEnabled(int subId) {
4656 return isUserDataEnabled(subId);
4657 }
4658
4659 /**
4660 * Get whether mobile data is enabled per user setting.
4661 *
4662 * There are other factors deciding whether mobile data is actually enabled, but they are
4663 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004664 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004665 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004666 *
4667 * @return {@code true} if data is enabled else {@code false}
4668 */
4669 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004670 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004671 try {
4672 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4673 null);
4674 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004675 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4676 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004677 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004678
4679 final long identity = Binder.clearCallingIdentity();
4680 try {
4681 int phoneId = mSubscriptionController.getPhoneId(subId);
4682 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4683 Phone phone = PhoneFactory.getPhone(phoneId);
4684 if (phone != null) {
4685 boolean retVal = phone.isUserDataEnabled();
4686 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4687 return retVal;
4688 } else {
4689 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4690 return false;
4691 }
4692 } finally {
4693 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004694 }
4695 }
4696
4697 /**
4698 * Get whether mobile data is enabled.
4699 *
4700 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4701 * whether mobile data is actually enabled.
4702 *
4703 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4704 *
4705 * @return {@code true} if data is enabled else {@code false}
4706 */
4707 @Override
4708 public boolean isDataEnabled(int subId) {
4709 try {
4710 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4711 null);
4712 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004713 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4714 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004715 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004716
4717 final long identity = Binder.clearCallingIdentity();
4718 try {
4719 int phoneId = mSubscriptionController.getPhoneId(subId);
4720 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4721 Phone phone = PhoneFactory.getPhone(phoneId);
4722 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08004723 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004724 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4725 return retVal;
4726 } else {
4727 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4728 return false;
4729 }
4730 } finally {
4731 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004732 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004733 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004734
4735 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004736 public int getCarrierPrivilegeStatus(int subId) {
4737 final Phone phone = getPhone(subId);
4738 if (phone == null) {
4739 loge("getCarrierPrivilegeStatus: Invalid subId");
4740 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4741 }
4742 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004743 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004744 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004745 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4746 }
4747 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004748 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004749 }
Junda Liu29340342014-07-10 15:23:27 -07004750
4751 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004752 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4753 final Phone phone = getPhone(subId);
4754 if (phone == null) {
4755 loge("getCarrierPrivilegeStatus: Invalid subId");
4756 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4757 }
4758 UiccProfile profile =
4759 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4760 if (profile == null) {
4761 loge("getCarrierPrivilegeStatus: No UICC");
4762 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4763 }
4764 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4765 }
4766
4767 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07004768 public int checkCarrierPrivilegesForPackage(String pkgName) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004769 final Phone defaultPhone = getDefaultPhone();
Junda Liu317d70b2016-03-08 09:33:53 -08004770 if (TextUtils.isEmpty(pkgName))
4771 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004772 UiccCard card = UiccController.getInstance().getUiccCard(defaultPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004773 if (card == null) {
4774 loge("checkCarrierPrivilegesForPackage: No UICC");
4775 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4776 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004777 return card.getCarrierPrivilegeStatus(defaultPhone.getContext().getPackageManager(),
4778 pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004779 }
4780
4781 @Override
4782 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004783 if (TextUtils.isEmpty(pkgName))
4784 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004785 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4786 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4787 UiccCard card = UiccController.getInstance().getUiccCard(i);
4788 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004789 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004790 continue;
4791 }
4792
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004793 result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004794 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4795 break;
4796 }
4797 }
4798
4799 return result;
Junda Liu29340342014-07-10 15:23:27 -07004800 }
Derek Tan89e89d42014-07-08 17:00:10 -07004801
4802 @Override
Junda Liue64de782015-04-16 17:19:16 -07004803 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4804 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4805 loge("phoneId " + phoneId + " is not valid.");
4806 return null;
4807 }
4808 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004809 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004810 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004811 return null ;
4812 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004813 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004814 }
4815
Amith Yamasani6e118872016-02-19 12:53:51 -08004816 @Override
4817 public List<String> getPackagesWithCarrierPrivileges() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004818 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08004819 List<String> privilegedPackages = new ArrayList<>();
4820 List<PackageInfo> packages = null;
4821 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4822 UiccCard card = UiccController.getInstance().getUiccCard(i);
4823 if (card == null) {
4824 // No UICC in that slot.
4825 continue;
4826 }
4827 if (card.hasCarrierPrivilegeRules()) {
4828 if (packages == null) {
4829 // Only check packages in user 0 for now
4830 packages = pm.getInstalledPackagesAsUser(
4831 PackageManager.MATCH_DISABLED_COMPONENTS
4832 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4833 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
4834 }
4835 for (int p = packages.size() - 1; p >= 0; p--) {
4836 PackageInfo pkgInfo = packages.get(p);
4837 if (pkgInfo != null && pkgInfo.packageName != null
4838 && card.getCarrierPrivilegeStatus(pkgInfo)
4839 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4840 privilegedPackages.add(pkgInfo.packageName);
4841 }
4842 }
4843 }
4844 }
4845 return privilegedPackages;
4846 }
4847
Wink Savilleb564aae2014-10-23 10:18:09 -07004848 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004849 final Phone phone = getPhone(subId);
4850 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004851 if (card == null) {
4852 loge("getIccId: No UICC");
4853 return null;
4854 }
4855 String iccId = card.getIccId();
4856 if (TextUtils.isEmpty(iccId)) {
4857 loge("getIccId: ICC ID is null or empty.");
4858 return null;
4859 }
4860 return iccId;
4861 }
4862
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004863 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004864 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4865 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004866 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4867 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004868
Malcolm Chend965c8b2018-02-28 15:00:40 -08004869 final long identity = Binder.clearCallingIdentity();
4870 try {
4871 final String iccId = getIccId(subId);
4872 final Phone phone = getPhone(subId);
4873 if (phone == null) {
4874 return false;
4875 }
4876 final String subscriberId = phone.getSubscriberId();
4877
4878 if (DBG_MERGE) {
4879 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4880 + subscriberId + " to " + number);
4881 }
4882
4883 if (TextUtils.isEmpty(iccId)) {
4884 return false;
4885 }
4886
4887 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4888
4889 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4890 if (alphaTag == null) {
4891 editor.remove(alphaTagPrefKey);
4892 } else {
4893 editor.putString(alphaTagPrefKey, alphaTag);
4894 }
4895
4896 // Record both the line number and IMSI for this ICCID, since we need to
4897 // track all merged IMSIs based on line number
4898 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4899 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4900 if (number == null) {
4901 editor.remove(numberPrefKey);
4902 editor.remove(subscriberPrefKey);
4903 } else {
4904 editor.putString(numberPrefKey, number);
4905 editor.putString(subscriberPrefKey, subscriberId);
4906 }
4907
4908 editor.commit();
4909 return true;
4910 } finally {
4911 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004912 }
Derek Tan7226c842014-07-02 17:42:23 -07004913 }
4914
4915 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004916 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004917 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004918 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004919 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004920 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004921 return null;
4922 }
Derek Tan97ebb422014-09-05 16:55:38 -07004923
Malcolm Chend965c8b2018-02-28 15:00:40 -08004924 final long identity = Binder.clearCallingIdentity();
4925 try {
4926 String iccId = getIccId(subId);
4927 if (iccId != null) {
4928 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4929 if (DBG_MERGE) {
4930 log("getLine1NumberForDisplay returning "
4931 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4932 }
4933 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004934 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004935 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4936 return null;
4937 } finally {
4938 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004939 }
Derek Tan7226c842014-07-02 17:42:23 -07004940 }
4941
4942 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004943 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004944 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004945 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004946 return null;
4947 }
Derek Tan97ebb422014-09-05 16:55:38 -07004948
Malcolm Chend965c8b2018-02-28 15:00:40 -08004949 final long identity = Binder.clearCallingIdentity();
4950 try {
4951 String iccId = getIccId(subId);
4952 if (iccId != null) {
4953 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4954 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4955 }
4956 return null;
4957 } finally {
4958 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004959 }
Derek Tan7226c842014-07-02 17:42:23 -07004960 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004961
4962 @Override
Jordan Liu9775d4b2019-05-06 14:45:15 -07004963 public String[] getMergedSubscriberIds(int subId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004964 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4965 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004966 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004967 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4968 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004969 return null;
4970 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004971
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004972 final long identity = Binder.clearCallingIdentity();
4973 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004974 final Context context = mApp;
Malcolm Chend965c8b2018-02-28 15:00:40 -08004975 final TelephonyManager tele = TelephonyManager.from(context);
4976 final SubscriptionManager sub = SubscriptionManager.from(context);
4977
4978 // Figure out what subscribers are currently active
4979 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
4980 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4981 // the process, where TelephonyManager was instantiated.
4982 // Otherwise AppOps check will fail.
4983
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004984 final int[] subIds = sub.getActiveSubscriptionIdList();
Jordan Liu9775d4b2019-05-06 14:45:15 -07004985 for (int id : subIds) {
4986 // Only consider subs which match the current subId
4987 // This logic can be simplified. See b/131189269 for progress.
4988 if (subId != id) {
4989 continue;
4990 }
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004991 activeSubscriberIds.add(tele.getSubscriberId(subId));
4992 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004993
4994 // First pass, find a number override for an active subscriber
4995 String mergeNumber = null;
4996 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
4997 for (String key : prefs.keySet()) {
4998 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
4999 final String subscriberId = (String) prefs.get(key);
5000 if (activeSubscriberIds.contains(subscriberId)) {
5001 final String iccId = key.substring(
5002 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5003 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5004 mergeNumber = (String) prefs.get(numberKey);
5005 if (DBG_MERGE) {
5006 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5007 + " for active subscriber " + subscriberId);
5008 }
5009 if (!TextUtils.isEmpty(mergeNumber)) {
5010 break;
5011 }
5012 }
5013 }
5014 }
5015
5016 // Shortcut when no active merged subscribers
5017 if (TextUtils.isEmpty(mergeNumber)) {
5018 return null;
5019 }
5020
5021 // Second pass, find all subscribers under that line override
5022 final ArraySet<String> result = new ArraySet<>();
5023 for (String key : prefs.keySet()) {
5024 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5025 final String number = (String) prefs.get(key);
5026 if (mergeNumber.equals(number)) {
5027 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5028 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5029 final String subscriberId = (String) prefs.get(subscriberKey);
5030 if (!TextUtils.isEmpty(subscriberId)) {
5031 result.add(subscriberId);
5032 }
5033 }
5034 }
5035 }
5036
5037 final String[] resultArray = result.toArray(new String[result.size()]);
5038 Arrays.sort(resultArray);
5039 if (DBG_MERGE) {
5040 Slog.d(LOG_TAG,
5041 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5042 }
5043 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005044 } finally {
5045 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005046 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005047 }
5048
5049 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005050 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005051 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5052 subId, "setOperatorBrandOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005053
5054 final long identity = Binder.clearCallingIdentity();
5055 try {
5056 final Phone phone = getPhone(subId);
5057 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5058 } finally {
5059 Binder.restoreCallingIdentity(identity);
5060 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005061 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005062
5063 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005064 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005065 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5066 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005067 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005068
5069 final long identity = Binder.clearCallingIdentity();
5070 try {
5071 final Phone phone = getPhone(subId);
5072 if (phone == null) {
5073 return false;
5074 }
5075 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5076 cdmaNonRoamingList);
5077 } finally {
5078 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005079 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005080 }
5081
5082 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005083 @Deprecated
5084 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5085 enforceModifyPermission();
5086
5087 int returnValue = 0;
5088 try {
vagdevie435a3e2018-08-15 16:01:53 -07005089 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005090 if(result.exception == null) {
5091 if (result.result != null) {
5092 byte[] responseData = (byte[])(result.result);
5093 if(responseData.length > oemResp.length) {
5094 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5095 responseData.length + "bytes. Buffer Size is " +
5096 oemResp.length + "bytes.");
5097 }
5098 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5099 returnValue = responseData.length;
5100 }
5101 } else {
5102 CommandException ex = (CommandException) result.exception;
5103 returnValue = ex.getCommandError().ordinal();
5104 if(returnValue > 0) returnValue *= -1;
5105 }
5106 } catch (RuntimeException e) {
5107 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5108 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5109 if(returnValue > 0) returnValue *= -1;
5110 }
5111
5112 return returnValue;
5113 }
5114
5115 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005116 public void setRadioCapability(RadioAccessFamily[] rafs) {
5117 try {
5118 ProxyController.getInstance().setRadioCapability(rafs);
5119 } catch (RuntimeException e) {
5120 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5121 }
5122 }
5123
5124 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005125 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005126 Phone phone = PhoneFactory.getPhone(phoneId);
chen xufeeed752018-10-26 14:17:57 -07005127 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005128 if (phone == null) {
chen xufeeed752018-10-26 14:17:57 -07005129 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005130 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005131 final long identity = Binder.clearCallingIdentity();
5132 try {
chen xufeeed752018-10-26 14:17:57 -07005133 TelephonyPermissions
5134 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5135 mApp, phone.getSubId(), "getRadioAccessFamily");
5136 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005137 } finally {
5138 Binder.restoreCallingIdentity(identity);
5139 }
chen xufeeed752018-10-26 14:17:57 -07005140 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005141 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005142
5143 @Override
5144 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005145 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005146 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005147
5148 final long identity = Binder.clearCallingIdentity();
5149 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005150 ImsManager.getInstance(defaultPhone.getContext(),
5151 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005152 } finally {
5153 Binder.restoreCallingIdentity(identity);
5154 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005155 }
5156
5157 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005158 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005159 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00005160 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005161 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005162 return false;
5163 }
Svet Ganovb320e182015-04-16 12:30:10 -07005164
Malcolm Chend965c8b2018-02-28 15:00:40 -08005165 final long identity = Binder.clearCallingIdentity();
5166 try {
5167 // Check the user preference and the system-level IMS setting. Even if the user has
5168 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5169 // In the long run, we may instead need to check if there exists a connection service
5170 // which can support video calling.
5171 ImsManager imsManager =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005172 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005173 return imsManager.isVtEnabledByPlatform()
5174 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5175 && imsManager.isVtEnabledByUser();
5176 } finally {
5177 Binder.restoreCallingIdentity(identity);
5178 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005179 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005180
Andrew Leea1239f22015-03-02 17:44:07 -08005181 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08005182 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
5183 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5184 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5185 return false;
5186 }
5187
5188 final long identity = Binder.clearCallingIdentity();
5189 try {
5190 CarrierConfigManager configManager =
5191 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005192 return configManager.getConfigForSubId(subId)
Malcolm Chend965c8b2018-02-28 15:00:40 -08005193 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5194 } finally {
5195 Binder.restoreCallingIdentity(identity);
5196 }
Andrew Leea1239f22015-03-02 17:44:07 -08005197 }
5198
5199 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08005200 public boolean isWorldPhone(int subId, String callingPackage) {
5201 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5202 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5203 return false;
5204 }
5205
5206 final long identity = Binder.clearCallingIdentity();
5207 try {
5208 CarrierConfigManager configManager =
5209 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005210 return configManager.getConfigForSubId(subId)
Malcolm Chend965c8b2018-02-28 15:00:40 -08005211 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5212 } finally {
5213 Binder.restoreCallingIdentity(identity);
5214 }
Andrew Leea1239f22015-03-02 17:44:07 -08005215 }
5216
Andrew Lee9431b832015-03-09 18:46:45 -07005217 @Override
5218 public boolean isTtyModeSupported() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005219 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005220 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005221 }
5222
5223 @Override
5224 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005225 final long identity = Binder.clearCallingIdentity();
5226 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005227 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005228 } finally {
5229 Binder.restoreCallingIdentity(identity);
5230 }
Andrew Lee9431b832015-03-09 18:46:45 -07005231 }
5232
Hall Liuf6668912018-10-31 17:05:23 -07005233 /**
5234 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5235 * support for the feature and device firmware support.
5236 *
5237 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5238 */
5239 @Override
5240 public boolean isRttSupported(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005241 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005242 final Phone phone = getPhone(subscriptionId);
5243 if (phone == null) {
5244 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5245 return false;
5246 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005247 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005248 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chend965c8b2018-02-28 15:00:40 -08005249 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5250 boolean isDeviceSupported =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005251 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005252 return isCarrierSupported && isDeviceSupported;
5253 } finally {
5254 Binder.restoreCallingIdentity(identity);
5255 }
Hall Liu98187582018-01-22 19:15:32 -08005256 }
5257
Hall Liuf6668912018-10-31 17:05:23 -07005258 /**
5259 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
5260 * both also support RTT.
5261 */
5262 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005263 final long identity = Binder.clearCallingIdentity();
5264 try {
Hall Liuf6668912018-10-31 17:05:23 -07005265 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005266 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005267 } finally {
5268 Binder.restoreCallingIdentity(identity);
5269 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005270 }
5271
Sanket Padawe7310cc72015-01-14 09:53:20 -08005272 /**
5273 * Returns the unique device ID of phone, for example, the IMEI for
5274 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5275 *
5276 * <p>Requires Permission:
5277 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5278 */
5279 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005280 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005281 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005282 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005283 return null;
5284 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005285 int subId = phone.getSubId();
5286 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5287 mApp, subId, callingPackage, "getDeviceId")) {
5288 return null;
5289 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005290
5291 final long identity = Binder.clearCallingIdentity();
5292 try {
5293 return phone.getDeviceId();
5294 } finally {
5295 Binder.restoreCallingIdentity(identity);
5296 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005297 }
5298
Ping Sunc67b7c22016-03-02 19:16:45 +08005299 /**
5300 * {@hide}
5301 * Returns the IMS Registration Status on a particular subid
5302 *
5303 * @param subId
5304 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005305 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005306 Phone phone = getPhone(subId);
5307 if (phone != null) {
5308 return phone.isImsRegistered();
5309 } else {
5310 return false;
5311 }
5312 }
5313
Santos Cordon7a1885b2015-02-03 11:15:19 -08005314 @Override
5315 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005316 final long identity = Binder.clearCallingIdentity();
5317 try {
5318 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5319 } finally {
5320 Binder.restoreCallingIdentity(identity);
5321 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005322 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005323
Tyler Gunn327a9722019-04-03 15:28:53 -07005324 @Override
5325 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5326 final long identity = Binder.clearCallingIdentity();
5327 try {
5328 Phone phone = getPhone(subscriptionId);
5329 if (phone == null) {
5330 return null;
5331 }
5332 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5333 } finally {
5334 Binder.restoreCallingIdentity(identity);
5335 }
5336 }
5337
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005338 /**
5339 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005340 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005341 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005342 final long identity = Binder.clearCallingIdentity();
5343 try {
5344 Phone phone = getPhone(subId);
5345 if (phone != null) {
5346 return phone.isWifiCallingEnabled();
5347 } else {
5348 return false;
5349 }
5350 } finally {
5351 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005352 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005353 }
5354
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005355 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005356 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005357 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005358 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005359 final long identity = Binder.clearCallingIdentity();
5360 try {
5361 Phone phone = getPhone(subId);
5362 if (phone != null) {
5363 return phone.isVideoEnabled();
5364 } else {
5365 return false;
5366 }
5367 } finally {
5368 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005369 }
5370 }
5371
5372 /**
5373 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5374 * defined in {@link ImsRegistrationImplBase}.
5375 */
5376 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005377 final long identity = Binder.clearCallingIdentity();
5378 try {
5379 Phone phone = getPhone(subId);
5380 if (phone != null) {
5381 return phone.getImsRegistrationTech();
5382 } else {
5383 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5384 }
5385 } finally {
5386 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005387 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005388 }
5389
Stuart Scott8eef64f2015-04-08 15:13:54 -07005390 @Override
5391 public void factoryReset(int subId) {
5392 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005393 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5394 return;
5395 }
5396
Svet Ganovcc087f82015-05-12 20:35:54 -07005397 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005398
Svet Ganovcc087f82015-05-12 20:35:54 -07005399 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005400 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5401 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005402 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005403 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005404 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005405 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5406 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005407 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005408 // There has been issues when Sms raw table somehow stores orphan
5409 // fragments. They lead to garbled message when new fragments come
5410 // in and combined with those stale ones. In case this happens again,
5411 // user can reset all network settings which will clean up this table.
5412 cleanUpSmsRawTable(getDefaultPhone().getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07005413 } finally {
5414 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005415 }
5416 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005417
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005418 private void cleanUpSmsRawTable(Context context) {
5419 ContentResolver resolver = context.getContentResolver();
5420 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5421 resolver.delete(uri, null, null);
5422 }
5423
Narayan Kamath1c496c22015-04-16 14:40:19 +01005424 @Override
chen xu2e6dfec2019-01-21 23:31:38 -08005425 public String getSimLocaleForSubscriber(int subId) {
5426 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5427 final Phone phone = getPhone(subId);
5428 if (phone == null) {
5429 log("getSimLocaleForSubscriber, invalid subId");
Pengquan Meng9c291482019-01-28 16:26:29 -08005430 return null;
chen xu2e6dfec2019-01-21 23:31:38 -08005431 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005432 final long identity = Binder.clearCallingIdentity();
5433 try {
chen xu2e6dfec2019-01-21 23:31:38 -08005434 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5435 phone.getContext().getOpPackageName());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005436 // Try and fetch the locale from the carrier properties or from the SIM language
5437 // preferences (EF-PL and EF-LI)...
5438 final int mcc = info.getMcc();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005439 String simLanguage = null;
chen xu2e6dfec2019-01-21 23:31:38 -08005440 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5441 if (localeFromDefaultSim != null) {
5442 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5443 if (DBG) log("Using locale from subId: " + subId + " locale: "
5444 + localeFromDefaultSim);
5445 return localeFromDefaultSim.toLanguageTag();
5446 } else {
5447 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005448 }
5449 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005450
Malcolm Chend965c8b2018-02-28 15:00:40 -08005451 // The SIM language preferences only store a language (e.g. fr = French), not an
5452 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5453 // the SIM and carrier preferences does not include a country we add the country
5454 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005455 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005456 if (mccLocale != null) {
chen xu2e6dfec2019-01-21 23:31:38 -08005457 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005458 return mccLocale.toLanguageTag();
5459 }
5460
5461 if (DBG) log("No locale found - returning null");
5462 return null;
5463 } finally {
5464 Binder.restoreCallingIdentity(identity);
5465 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005466 }
5467
5468 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005469 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005470 }
5471
Malcolm Chend965c8b2018-02-28 15:00:40 -08005472 /**
5473 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5474 */
5475 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005476 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005477 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005478
Chenjie Yu1ba97252018-01-11 18:16:20 -08005479 private final ModemActivityInfo mLastModemActivityInfo =
5480 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
5481
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005482 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005483 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5484 * representing the state of the modem.
5485 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005486 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5487 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005488 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005489 */
5490 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005491 public void requestModemActivityInfo(ResultReceiver result) {
5492 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005493 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005494
5495 final long identity = Binder.clearCallingIdentity();
5496 try {
5497 ModemActivityInfo ret = null;
5498 synchronized (mLastModemActivityInfo) {
vagdevie435a3e2018-08-15 16:01:53 -07005499 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5500 CMD_GET_MODEM_ACTIVITY_INFO,
5501 null, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005502 if (isModemActivityInfoValid(info)) {
5503 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
5504 for (int i = 0; i < mergedTxTimeMs.length; i++) {
5505 mergedTxTimeMs[i] =
5506 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
5507 }
5508 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
5509 mLastModemActivityInfo.setSleepTimeMillis(
5510 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
5511 mLastModemActivityInfo.setIdleTimeMillis(
5512 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
5513 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
5514 mLastModemActivityInfo.setRxTimeMillis(
5515 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
5516 mLastModemActivityInfo.setEnergyUsed(
5517 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005518 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005519 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
5520 mLastModemActivityInfo.getSleepTimeMillis(),
5521 mLastModemActivityInfo.getIdleTimeMillis(),
5522 mLastModemActivityInfo.getTxTimeMillis(),
5523 mLastModemActivityInfo.getRxTimeMillis(),
5524 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005525 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005526 Bundle bundle = new Bundle();
5527 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
5528 result.send(0, bundle);
5529 } finally {
5530 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005531 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005532 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005533
Siddharth Rayf5d29552018-06-17 15:02:38 -07005534 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
5535 // less than total activity duration.
5536 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
5537 if (info == null) {
5538 return false;
5539 }
5540 int activityDurationMs =
5541 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
5542 int totalTxTimeMs = 0;
5543 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
5544 totalTxTimeMs += info.getTxTimeMillis()[i];
5545 }
5546 return (info.isValid()
5547 && (info.getSleepTimeMillis() <= activityDurationMs)
5548 && (info.getIdleTimeMillis() <= activityDurationMs)
5549 && (info.getRxTimeMillis() <= activityDurationMs)
5550 && (totalTxTimeMs <= activityDurationMs));
5551 }
5552
Jack Yu85bd38a2015-11-09 11:34:32 -08005553 /**
5554 * {@hide}
5555 * Returns the service state information on specified subscription.
5556 */
5557 @Override
5558 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005559 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005560 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08005561 return null;
5562 }
5563
Hall Liuf19c44f2018-11-27 14:38:17 -08005564 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
5565 LocationAccessPolicy.checkLocationPermission(mApp,
5566 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5567 .setCallingPackage(callingPackage)
5568 .setCallingPid(Binder.getCallingPid())
5569 .setCallingUid(Binder.getCallingUid())
5570 .setMethod("getServiceStateForSubscriber")
Hall Liu8b0cba22019-04-17 13:37:11 -07005571 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005572 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5573 .build());
5574
5575 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
5576 LocationAccessPolicy.checkLocationPermission(mApp,
5577 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5578 .setCallingPackage(callingPackage)
5579 .setCallingPid(Binder.getCallingPid())
5580 .setCallingUid(Binder.getCallingUid())
5581 .setMethod("getServiceStateForSubscriber")
Hall Liu8b0cba22019-04-17 13:37:11 -07005582 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005583 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5584 .build());
5585 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
5586 boolean hasFinePermission =
5587 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5588 boolean hasCoarsePermission =
5589 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5590
Malcolm Chend965c8b2018-02-28 15:00:40 -08005591 final long identity = Binder.clearCallingIdentity();
5592 try {
5593 final Phone phone = getPhone(subId);
5594 if (phone == null) {
5595 return null;
5596 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005597
Hall Liuf19c44f2018-11-27 14:38:17 -08005598 ServiceState ss = phone.getServiceState();
5599
5600 // Scrub out the location info in ServiceState depending on what level of access
5601 // the caller has.
5602 if (hasFinePermission) return ss;
5603 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
5604 return ss.sanitizeLocationInfo(true);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005605 } finally {
5606 Binder.restoreCallingIdentity(identity);
5607 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005608 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005609
5610 /**
5611 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
5612 *
5613 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5614 * voicemail ringtone.
5615 * @return The URI for the ringtone to play when receiving a voicemail from a specific
5616 * PhoneAccount.
5617 */
5618 @Override
5619 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005620 final long identity = Binder.clearCallingIdentity();
5621 try {
5622 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5623 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005624 phone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005625 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005626
Malcolm Chend965c8b2018-02-28 15:00:40 -08005627 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
5628 } finally {
5629 Binder.restoreCallingIdentity(identity);
5630 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005631 }
5632
5633 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005634 * Sets the per-account voicemail ringtone.
5635 *
5636 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5637 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5638 *
5639 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5640 * voicemail ringtone.
5641 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5642 * PhoneAccount.
5643 */
5644 @Override
5645 public void setVoicemailRingtoneUri(String callingPackage,
5646 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005647 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005648 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5649 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005650 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005651 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5652 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5653 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005654 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005655
5656 final long identity = Binder.clearCallingIdentity();
5657 try {
5658 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5659 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005660 phone = defaultPhone;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005661 }
5662 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5663 } finally {
5664 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005665 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005666 }
5667
5668 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005669 * Returns whether vibration is set for voicemail notification in Phone settings.
5670 *
5671 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5672 * voicemail vibration setting.
5673 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5674 */
5675 @Override
5676 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005677 final long identity = Binder.clearCallingIdentity();
5678 try {
5679 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5680 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005681 phone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005682 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005683
Malcolm Chend965c8b2018-02-28 15:00:40 -08005684 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5685 } finally {
5686 Binder.restoreCallingIdentity(identity);
5687 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005688 }
5689
Youhan Wange64578a2016-05-02 15:32:42 -07005690 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005691 * Sets the per-account voicemail vibration.
5692 *
5693 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5694 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5695 *
5696 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5697 * voicemail vibration setting.
5698 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5699 * specific PhoneAccount.
5700 */
5701 @Override
5702 public void setVoicemailVibrationEnabled(String callingPackage,
5703 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005704 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005705 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5706 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005707 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005708 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5709 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5710 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005711 }
5712
Malcolm Chend965c8b2018-02-28 15:00:40 -08005713 final long identity = Binder.clearCallingIdentity();
5714 try {
5715 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5716 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005717 phone = defaultPhone;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005718 }
5719 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5720 } finally {
5721 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005722 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005723 }
5724
5725 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005726 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5727 *
5728 * @throws SecurityException if the caller does not have the required permission
5729 */
Brad Ebinger4c460712018-10-01 10:40:55 -07005730 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005731 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger4c460712018-10-01 10:40:55 -07005732 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005733 }
5734
5735 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005736 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5737 * permission.
5738 *
5739 * @throws SecurityException if the caller does not have the required permission
5740 */
5741 private void enforceSendSmsPermission() {
5742 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5743 }
5744
5745 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005746 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005747 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005748 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005749 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005750 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005751 final long identity = Binder.clearCallingIdentity();
5752 try {
5753 ComponentName componentName =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005754 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005755 if (componentName == null) {
5756 throw new SecurityException(
5757 "Caller not current active visual voicemail package[null]");
5758 }
5759 String vvmPackage = componentName.getPackageName();
5760 if (!callingPackage.equals(vvmPackage)) {
5761 throw new SecurityException("Caller not current active visual voicemail package["
5762 + vvmPackage + "]");
5763 }
5764 } finally {
5765 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005766 }
5767 }
5768
5769 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005770 * Return the application ID for the app type.
5771 *
5772 * @param subId the subscription ID that this request applies to.
5773 * @param appType the uicc app type.
5774 * @return Application ID for specificied app type, or null if no uicc.
5775 */
5776 @Override
5777 public String getAidForAppType(int subId, int appType) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005778 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005779 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005780
5781 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005782 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005783 if (phone == null) {
5784 return null;
5785 }
5786 String aid = null;
5787 try {
5788 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5789 .getApplicationByType(appType).getAid();
5790 } catch (Exception e) {
5791 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5792 }
5793 return aid;
5794 } finally {
5795 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005796 }
Youhan Wange64578a2016-05-02 15:32:42 -07005797 }
5798
Youhan Wang4001d252016-05-11 10:29:41 -07005799 /**
5800 * Return the Electronic Serial Number.
5801 *
5802 * @param subId the subscription ID that this request applies to.
5803 * @return ESN or null if error.
5804 */
5805 @Override
5806 public String getEsn(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005807 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005808 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005809
5810 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005811 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005812 if (phone == null) {
5813 return null;
5814 }
5815 String esn = null;
5816 try {
5817 esn = phone.getEsn();
5818 } catch (Exception e) {
5819 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5820 }
5821 return esn;
5822 } finally {
5823 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005824 }
Youhan Wang4001d252016-05-11 10:29:41 -07005825 }
5826
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005827 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005828 * Return the Preferred Roaming List Version.
5829 *
5830 * @param subId the subscription ID that this request applies to.
5831 * @return PRLVersion or null if error.
5832 */
5833 @Override
5834 public String getCdmaPrlVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005835 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005836 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005837
5838 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005839 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005840 if (phone == null) {
5841 return null;
5842 }
5843 String cdmaPrlVersion = null;
5844 try {
5845 cdmaPrlVersion = phone.getCdmaPrlVersion();
5846 } catch (Exception e) {
5847 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5848 }
5849 return cdmaPrlVersion;
5850 } finally {
5851 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005852 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005853 }
5854
5855 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005856 * Get snapshot of Telephony histograms
5857 * @return List of Telephony histograms
5858 * @hide
5859 */
5860 @Override
5861 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005862 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5863 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005864
5865 final long identity = Binder.clearCallingIdentity();
5866 try {
5867 return RIL.getTelephonyRILTimingHistograms();
5868 } finally {
5869 Binder.restoreCallingIdentity(identity);
5870 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005871 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005872
5873 /**
5874 * {@hide}
Michele Berionne0963c862018-11-27 18:57:59 -08005875 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
5876 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005877 * Require system privileges. In the future we may add this to carrier APIs.
5878 *
Michele Berionne0963c862018-11-27 18:57:59 -08005879 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005880 */
5881 @Override
Michele Berionne0963c862018-11-27 18:57:59 -08005882 @TelephonyManager.SetCarrierRestrictionResult
5883 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005884 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005885 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005886
Michele Berionne0963c862018-11-27 18:57:59 -08005887 if (carrierRestrictionRules == null) {
5888 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08005889 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005890
Malcolm Chend965c8b2018-02-28 15:00:40 -08005891 final long identity = Binder.clearCallingIdentity();
5892 try {
Michele Berionne0963c862018-11-27 18:57:59 -08005893 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdevie435a3e2018-08-15 16:01:53 -07005894 workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005895 } finally {
5896 Binder.restoreCallingIdentity(identity);
5897 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005898 }
5899
5900 /**
5901 * {@hide}
Michele Berionne0963c862018-11-27 18:57:59 -08005902 * Get the allowed carrier list and the excluded carrier list, including the priority between
5903 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005904 * Require system privileges. In the future we may add this to carrier APIs.
5905 *
Michele Berionne0963c862018-11-27 18:57:59 -08005906 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07005907 */
5908 @Override
Michele Berionne0963c862018-11-27 18:57:59 -08005909 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger4c460712018-10-01 10:40:55 -07005910 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdevie435a3e2018-08-15 16:01:53 -07005911 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005912
5913 final long identity = Binder.clearCallingIdentity();
5914 try {
Michele Berionne0963c862018-11-27 18:57:59 -08005915 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
5916 if (response instanceof CarrierRestrictionRules) {
5917 return (CarrierRestrictionRules) response;
5918 }
5919 // Response is an Exception of some kind,
5920 // which is signalled to the user as a NULL retval
5921 return null;
5922 } catch (Exception e) {
5923 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
5924 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005925 } finally {
5926 Binder.restoreCallingIdentity(identity);
5927 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005928 }
5929
fionaxu59545b42016-05-25 15:53:37 -07005930 /**
5931 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5932 * @param subId the subscription ID that this action applies to.
5933 * @param enabled control enable or disable metered apns.
5934 * {@hide}
5935 */
5936 @Override
5937 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5938 enforceModifyPermission();
5939 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005940
5941 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005942 if (phone == null) {
5943 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5944 return;
5945 }
5946 try {
5947 phone.carrierActionSetMeteredApnsEnabled(enabled);
5948 } catch (Exception e) {
5949 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005950 } finally {
5951 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005952 }
5953 }
5954
5955 /**
5956 * Action set from carrier signalling broadcast receivers to enable/disable radio
5957 * @param subId the subscription ID that this action applies to.
5958 * @param enabled control enable or disable radio.
5959 * {@hide}
5960 */
5961 @Override
5962 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5963 enforceModifyPermission();
5964 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005965
5966 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005967 if (phone == null) {
5968 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5969 return;
5970 }
5971 try {
5972 phone.carrierActionSetRadioEnabled(enabled);
5973 } catch (Exception e) {
5974 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005975 } finally {
5976 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005977 }
5978 }
5979
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005980 /**
fionaxu8da9cb12017-05-23 15:02:46 -07005981 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
5982 * network status based on which carrier apps could apply actions accordingly,
5983 * enable/disable default url handler for example.
5984 *
5985 * @param subId the subscription ID that this action applies to.
5986 * @param report control start/stop reporting the default network status.
5987 * {@hide}
5988 */
5989 @Override
5990 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
5991 enforceModifyPermission();
5992 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005993
5994 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07005995 if (phone == null) {
5996 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
5997 return;
5998 }
5999 try {
6000 phone.carrierActionReportDefaultNetworkStatus(report);
6001 } catch (Exception e) {
6002 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08006003 } finally {
6004 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006005 }
6006 }
6007
6008 /**
fionaxud9622282017-07-17 17:51:30 -07006009 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6010 * @param subId the subscription ID that this action applies to.
6011 * {@hide}
6012 */
6013 @Override
6014 public void carrierActionResetAll(int subId) {
6015 enforceModifyPermission();
6016 final Phone phone = getPhone(subId);
6017 if (phone == null) {
6018 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6019 return;
6020 }
6021 try {
6022 phone.carrierActionResetAll();
6023 } catch (Exception e) {
6024 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6025 }
6026 }
6027
6028 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006029 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6030 * bug report is being generated.
6031 */
6032 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006033 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006034 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6035 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006036 writer.println("Permission Denial: can't dump Phone from pid="
6037 + Binder.getCallingPid()
6038 + ", uid=" + Binder.getCallingUid()
6039 + "without permission "
6040 + android.Manifest.permission.DUMP);
6041 return;
6042 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006043 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006044 }
Jack Yueb89b242016-06-22 13:27:47 -07006045
Brad Ebingerdac2f002018-04-03 15:17:52 -07006046 @Override
6047 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6048 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6049 throws RemoteException {
6050 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
6051 }
6052
Jack Yueb89b242016-06-22 13:27:47 -07006053 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006054 * Get aggregated video call data usage since boot.
6055 *
6056 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6057 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006058 * {@hide}
6059 */
6060 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006061 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006062 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6063 null);
6064
Malcolm Chend965c8b2018-02-28 15:00:40 -08006065 final long identity = Binder.clearCallingIdentity();
6066 try {
6067 // NetworkStatsService keeps tracking the active network interface and identity. It
6068 // records the delta with the corresponding network identity.
6069 // We just return the total video call data usage snapshot since boot.
6070 Phone phone = getPhone(subId);
6071 if (phone != null) {
6072 return phone.getVtDataUsage(perUidStats);
6073 }
6074 return null;
6075 } finally {
6076 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006077 }
Jack Yueb89b242016-06-22 13:27:47 -07006078 }
Jack Yu75ab2952016-07-08 14:29:33 -07006079
6080 /**
6081 * Policy control of data connection. Usually used when data limit is passed.
6082 * @param enabled True if enabling the data, otherwise disabling.
6083 * @param subId Subscription index
6084 * {@hide}
6085 */
6086 @Override
6087 public void setPolicyDataEnabled(boolean enabled, int subId) {
6088 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08006089
6090 final long identity = Binder.clearCallingIdentity();
6091 try {
6092 Phone phone = getPhone(subId);
6093 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08006094 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chend965c8b2018-02-28 15:00:40 -08006095 }
6096 } finally {
6097 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006098 }
6099 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006100
6101 /**
6102 * Get Client request stats
6103 * @return List of Client Request Stats
6104 * @hide
6105 */
6106 @Override
6107 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006108 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006109 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006110 return null;
6111 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006112 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006113
Malcolm Chend965c8b2018-02-28 15:00:40 -08006114 final long identity = Binder.clearCallingIdentity();
6115 try {
6116 if (phone != null) {
6117 return phone.getClientRequestStats();
6118 }
6119
6120 return null;
6121 } finally {
6122 Binder.restoreCallingIdentity(identity);
6123 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006124 }
6125
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006126 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006127 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006128 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006129 }
Jack Yueb4124c2017-02-16 15:32:43 -08006130
6131 /**
Grace Chen70990072017-03-24 17:21:30 -07006132 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006133 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006134 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006135 * @param state State of SIM (power down, power up, pass through)
6136 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6137 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6138 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006139 *
6140 **/
6141 @Override
Grace Chen70990072017-03-24 17:21:30 -07006142 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006143 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006144 Phone phone = PhoneFactory.getPhone(slotIndex);
6145
vagdevie435a3e2018-08-15 16:01:53 -07006146 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6147
Malcolm Chend965c8b2018-02-28 15:00:40 -08006148 final long identity = Binder.clearCallingIdentity();
6149 try {
6150 if (phone != null) {
vagdevie435a3e2018-08-15 16:01:53 -07006151 phone.setSimPowerState(state, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08006152 }
6153 } finally {
6154 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006155 }
6156 }
Shuo Qiandd210312017-04-12 22:11:33 +00006157
Tyler Gunn65d45c22017-06-05 11:22:26 -07006158 private boolean isUssdApiAllowed(int subId) {
6159 CarrierConfigManager configManager =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006160 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006161 if (configManager == null) {
6162 return false;
6163 }
6164 PersistableBundle pb = configManager.getConfigForSubId(subId);
6165 if (pb == null) {
6166 return false;
6167 }
6168 return pb.getBoolean(
6169 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6170 }
6171
Shuo Qiandd210312017-04-12 22:11:33 +00006172 /**
6173 * Check if phone is in emergency callback mode
6174 * @return true if phone is in emergency callback mode
6175 * @param subId sub id
6176 */
goneil9c5f4872017-12-05 14:07:56 -08006177 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006178 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07006179 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006180 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08006181
6182 final long identity = Binder.clearCallingIdentity();
6183 try {
6184 if (phone != null) {
6185 return phone.isInEcm();
6186 } else {
6187 return false;
6188 }
6189 } finally {
6190 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006191 }
6192 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006193
6194 /**
6195 * Get the current signal strength information for the given subscription.
6196 * Because this information is not updated when the device is in a low power state
6197 * it should not be relied-upon to be current.
6198 * @param subId Subscription index
6199 * @return the most recent cached signal strength info from the modem
6200 */
6201 @Override
6202 public SignalStrength getSignalStrength(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08006203 final long identity = Binder.clearCallingIdentity();
6204 try {
6205 Phone p = getPhone(subId);
6206 if (p == null) {
6207 return null;
6208 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006209
Malcolm Chend965c8b2018-02-28 15:00:40 -08006210 return p.getSignalStrength();
6211 } finally {
6212 Binder.restoreCallingIdentity(identity);
6213 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006214 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006215
Pengquan Meng9140aec2018-08-22 14:49:57 -07006216 /**
chen xu907e5a22018-10-11 13:21:04 -07006217 * Get the current modem radio state for the given slot.
6218 * @param slotIndex slot index.
6219 * @param callingPackage the name of the package making the call.
6220 * @return the current radio power state from the modem
6221 */
6222 @Override
6223 public int getRadioPowerState(int slotIndex, String callingPackage) {
6224 Phone phone = PhoneFactory.getPhone(slotIndex);
6225 if (phone != null) {
6226 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6227 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
6228 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6229 }
6230
6231 final long identity = Binder.clearCallingIdentity();
6232 try {
6233 return phone.getRadioPowerState();
6234 } finally {
6235 Binder.restoreCallingIdentity(identity);
6236 }
6237 }
6238 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6239 }
6240
6241 /**
Pengquan Meng9140aec2018-08-22 14:49:57 -07006242 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6243 *
6244 * <p>Requires one of the following permissions:
6245 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6246 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6247 * privileges.
6248 *
6249 * @param subId subscription id
6250 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6251 * {@code false}.
6252 */
6253 @Override
6254 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006255 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6256 null /* message */);
6257
Pengquan Meng0c05b502018-09-06 09:59:22 -07006258 boolean isEnabled = false;
6259 final long identity = Binder.clearCallingIdentity();
Pengquan Meng9140aec2018-08-22 14:49:57 -07006260 try {
Pengquan Meng0c05b502018-09-06 09:59:22 -07006261 Phone phone = getPhone(subId);
6262 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng9140aec2018-08-22 14:49:57 -07006263 } catch (Exception e) {
6264 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6265 mApp, subId, "isDataRoamingEnabled");
Pengquan Meng0c05b502018-09-06 09:59:22 -07006266 } finally {
6267 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07006268 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07006269 return isEnabled;
Pengquan Meng9140aec2018-08-22 14:49:57 -07006270 }
6271
6272
6273 /**
6274 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6275 *
6276 * <p> Requires permission:
6277 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6278 * privileges.
6279 *
6280 * @param subId subscription id
6281 * @param isEnabled {@code true} means enable, {@code false} means disable.
6282 */
6283 @Override
6284 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006285 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6286 mApp, subId, "setDataRoamingEnabled");
6287
Pengquan Meng0c05b502018-09-06 09:59:22 -07006288 final long identity = Binder.clearCallingIdentity();
6289 try {
Pengquan Meng0c05b502018-09-06 09:59:22 -07006290 Phone phone = getPhone(subId);
6291 if (phone != null) {
6292 phone.setDataRoamingEnabled(isEnabled);
6293 }
6294 } finally {
6295 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07006296 }
6297 }
6298
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006299 @Override
Pengquan Meng312de0c2018-10-03 12:19:13 -07006300 public boolean isManualNetworkSelectionAllowed(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006301 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6302 mApp, subId, "isManualNetworkSelectionAllowed");
6303
Pengquan Meng312de0c2018-10-03 12:19:13 -07006304 boolean isAllowed = true;
6305 final long identity = Binder.clearCallingIdentity();
6306 try {
Pengquan Meng312de0c2018-10-03 12:19:13 -07006307 Phone phone = getPhone(subId);
6308 if (phone != null) {
6309 isAllowed = phone.isCspPlmnEnabled();
6310 }
6311 } finally {
6312 Binder.restoreCallingIdentity(identity);
6313 }
6314 return isAllowed;
6315 }
6316
6317 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006318 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu67997952019-04-22 15:10:43 -07006319 boolean hasReadPermission = false;
Jordan Liu53fdb782019-02-12 17:54:02 -08006320 try {
6321 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu67997952019-04-22 15:10:43 -07006322 hasReadPermission = true;
Jordan Liu53fdb782019-02-12 17:54:02 -08006323 } catch (SecurityException e) {
6324 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6325 // has carrier privileges on an active UICC
6326 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6327 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu67997952019-04-22 15:10:43 -07006328 throw new SecurityException("Caller does not have permission.");
Jordan Liu53fdb782019-02-12 17:54:02 -08006329 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006330 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006331
6332 final long identity = Binder.clearCallingIdentity();
6333 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006334 UiccController uiccController = UiccController.getInstance();
6335 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu67997952019-04-22 15:10:43 -07006336 if (hasReadPermission) {
6337 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006338 }
Jordan Liu67997952019-04-22 15:10:43 -07006339
6340 // Remove private info if the caller doesn't have access
6341 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6342 for (UiccCardInfo cardInfo : cardInfos) {
6343 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6344 // is available
6345 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
6346 if (card == null || card.getUiccProfile() == null) {
6347 // assume no access if the card or profile is unavailable
6348 filteredInfos.add(cardInfo.getUnprivileged());
6349 continue;
6350 }
6351 UiccProfile profile = card.getUiccProfile();
6352 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6353 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6354 filteredInfos.add(cardInfo);
6355 } else {
6356 filteredInfos.add(cardInfo.getUnprivileged());
6357 }
6358 }
6359 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08006360 } finally {
6361 Binder.restoreCallingIdentity(identity);
6362 }
6363 }
6364
6365 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006366 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger4c460712018-10-01 10:40:55 -07006367 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006368
Malcolm Chend965c8b2018-02-28 15:00:40 -08006369 final long identity = Binder.clearCallingIdentity();
6370 try {
6371 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6372 if (slots == null) {
6373 Rlog.i(LOG_TAG, "slots is null.");
6374 return null;
6375 }
6376
6377 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6378 for (int i = 0; i < slots.length; i++) {
6379 UiccSlot slot = slots[i];
6380 if (slot == null) {
6381 continue;
6382 }
6383
6384 String cardId;
6385 UiccCard card = slot.getUiccCard();
6386 if (card != null) {
6387 cardId = card.getCardId();
6388 } else {
6389 cardId = slot.getIccId();
6390 }
6391
Jordan Liu857451f2019-05-09 16:35:35 -07006392 if (cardId != null) {
6393 // if cardId is an ICCID, strip off trailing Fs before exposing to user
6394 // if cardId is an EID, it's all digits so this is fine
6395 cardId = IccUtils.stripTrailingFs(cardId);
6396 }
6397
Malcolm Chend965c8b2018-02-28 15:00:40 -08006398 int cardState = 0;
6399 switch (slot.getCardState()) {
6400 case CARDSTATE_ABSENT:
6401 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6402 break;
6403 case CARDSTATE_PRESENT:
6404 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6405 break;
6406 case CARDSTATE_ERROR:
6407 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6408 break;
6409 case CARDSTATE_RESTRICTED:
6410 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6411 break;
6412 default:
6413 break;
6414
6415 }
6416
6417 infos[i] = new UiccSlotInfo(
6418 slot.isActive(),
6419 slot.isEuicc(),
6420 cardId,
6421 cardState,
6422 slot.getPhoneId(),
Jordan Liuef65d872019-02-14 12:56:40 -08006423 slot.isExtendedApduSupported(),
6424 slot.isRemovable());
Malcolm Chend965c8b2018-02-28 15:00:40 -08006425 }
6426 return infos;
6427 } finally {
6428 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006429 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006430 }
6431
6432 @Override
6433 public boolean switchSlots(int[] physicalSlots) {
6434 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08006435
6436 final long identity = Binder.clearCallingIdentity();
6437 try {
6438 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6439 } finally {
6440 Binder.restoreCallingIdentity(identity);
6441 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006442 }
Jack Yu4c988042018-02-27 15:30:01 -08006443
6444 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006445 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006446 final long identity = Binder.clearCallingIdentity();
6447 try {
6448 return UiccController.getInstance().getCardIdForDefaultEuicc();
6449 } finally {
6450 Binder.restoreCallingIdentity(identity);
6451 }
6452 }
6453
6454 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006455 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6456 enforceModifyPermission();
6457 final Phone phone = getPhone(subId);
6458 if (phone == null) {
6459 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6460 return;
6461 }
6462
Malcolm Chend965c8b2018-02-28 15:00:40 -08006463 final long identity = Binder.clearCallingIdentity();
6464 try {
6465 phone.setRadioIndicationUpdateMode(filters, mode);
6466 } finally {
6467 Binder.restoreCallingIdentity(identity);
6468 }
Jack Yu4c988042018-02-27 15:30:01 -08006469 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006470
6471 /**
goneil47ffb6e2018-04-06 15:40:58 -07006472 * A test API to reload the UICC profile.
6473 *
6474 * <p>Requires that the calling app has permission
6475 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6476 * @hide
6477 */
6478 @Override
6479 public void refreshUiccProfile(int subId) {
6480 enforceModifyPermission();
6481
6482 final long identity = Binder.clearCallingIdentity();
6483 try {
6484 Phone phone = getPhone(subId);
6485 if (phone == null) {
6486 return;
6487 }
6488 UiccCard uiccCard = phone.getUiccCard();
6489 if (uiccCard == null) {
6490 return;
6491 }
6492 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6493 if (uiccProfile == null) {
6494 return;
6495 }
6496 uiccProfile.refresh();
6497 } finally {
6498 Binder.restoreCallingIdentity(identity);
6499 }
6500 }
6501
6502 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006503 * Returns false if the mobile data is disabled by default, otherwise return true.
6504 */
6505 private boolean getDefaultDataEnabled() {
6506 return "true".equalsIgnoreCase(
6507 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
6508 }
6509
6510 /**
6511 * Returns true if the data roaming is enabled by default, i.e the system property
6512 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
6513 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
6514 */
6515 private boolean getDefaultDataRoamingEnabled(int subId) {
6516 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006517 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006518 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
6519 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
6520 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
6521 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
6522 return isDataRoamingEnabled;
6523 }
6524
6525 /**
6526 * Returns the default network type for the given {@code subId}, if the default network type is
6527 * not set, return {@link Phone#PREFERRED_NT_MODE}.
6528 */
6529 private int getDefaultNetworkType(int subId) {
6530 return Integer.parseInt(
6531 TelephonyManager.getTelephonyProperty(
6532 mSubscriptionController.getPhoneId(subId),
6533 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
6534 String.valueOf(Phone.PREFERRED_NT_MODE)));
6535 }
fionaxua13278b2018-03-21 00:08:13 -07006536
6537 @Override
6538 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
6539 gid1, String gid2, String plmn, String spn) {
6540 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08006541
6542 final long identity = Binder.clearCallingIdentity();
6543 try {
6544 final Phone phone = getPhone(subId);
6545 if (phone == null) {
6546 loge("setCarrierTestOverride fails with invalid subId: " + subId);
6547 return;
6548 }
6549 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
6550 } finally {
6551 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006552 }
fionaxua13278b2018-03-21 00:08:13 -07006553 }
6554
6555 @Override
6556 public int getCarrierIdListVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07006557 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chend965c8b2018-02-28 15:00:40 -08006558
6559 final long identity = Binder.clearCallingIdentity();
6560 try {
6561 final Phone phone = getPhone(subId);
6562 if (phone == null) {
6563 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
6564 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
6565 }
6566 return phone.getCarrierIdListVersion();
6567 } finally {
6568 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006569 }
fionaxua13278b2018-03-21 00:08:13 -07006570 }
Malcolm Chenf144d942018-08-14 16:00:53 -07006571
6572 @Override
6573 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
6574 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6575 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
6576 return -1;
6577 }
6578
6579 final long identity = Binder.clearCallingIdentity();
6580 try {
6581 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
6582 } finally {
6583 Binder.restoreCallingIdentity(identity);
6584 }
6585 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07006586
6587 @Override
6588 public int getCdmaRoamingMode(int subId) {
6589 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6590 mApp, subId, "getCdmaRoamingMode");
6591
6592 final long identity = Binder.clearCallingIdentity();
6593 try {
6594 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
6595 } finally {
6596 Binder.restoreCallingIdentity(identity);
6597 }
6598 }
6599
6600 @Override
6601 public boolean setCdmaRoamingMode(int subId, int mode) {
6602 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6603 mApp, subId, "setCdmaRoamingMode");
6604
6605 final long identity = Binder.clearCallingIdentity();
6606 try {
6607 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
6608 } finally {
6609 Binder.restoreCallingIdentity(identity);
6610 }
6611 }
6612
6613 @Override
6614 public boolean setCdmaSubscriptionMode(int subId, int mode) {
6615 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6616 mApp, subId, "setCdmaSubscriptionMode");
6617
6618 final long identity = Binder.clearCallingIdentity();
6619 try {
6620 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
6621 } finally {
6622 Binder.restoreCallingIdentity(identity);
6623 }
6624 }
chen xu7ee67862018-10-30 22:27:10 -07006625
sqian2fff4a32018-11-05 14:18:37 -08006626 private void ensureUserRunning(int userId) {
6627 if (!mUserManager.isUserRunning(userId)) {
6628 throw new IllegalStateException("User " + userId + " does not exist or not running");
6629 }
6630 }
6631
6632 /**
6633 * Returns a list of SMS apps on a given user.
6634 *
6635 * Only the shell user (UID 2000 or 0) can call it.
6636 * Target user must be running.
6637 */
6638 @Override
6639 public String[] getSmsApps(int userId) {
6640 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
6641 ensureUserRunning(userId);
6642
6643 final Collection<SmsApplicationData> apps =
6644 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
6645
6646 String[] ret = new String[apps.size()];
6647 int i = 0;
6648 for (SmsApplicationData app : apps) {
6649 ret[i++] = app.mPackageName;
6650 }
6651 return ret;
6652 }
6653
6654 /**
6655 * Returns the default SMS app package name on a given user.
6656 *
6657 * Only the shell user (UID 2000 or 0) can call it.
6658 * Target user must be running.
6659 */
6660 @Override
6661 public String getDefaultSmsApp(int userId) {
6662 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
6663 ensureUserRunning(userId);
6664
6665 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
6666 /* updateIfNeeded= */ true, userId);
6667 return cn == null ? null : cn.getPackageName();
6668 }
6669
6670 /**
6671 * Set a package as the default SMS app on a given user.
6672 *
6673 * Only the shell user (UID 2000 or 0) can call it.
6674 * Target user must be running.
6675 */
6676 @Override
6677 public void setDefaultSmsApp(int userId, String packageName) {
6678 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
6679 ensureUserRunning(userId);
6680
6681 boolean found = false;
6682 for (String pkg : getSmsApps(userId)) {
6683 if (TextUtils.equals(packageName, pkg)) {
6684 found = true;
6685 break;
6686 }
6687 }
6688 if (!found) {
6689 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
6690 }
6691
6692 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
6693 }
6694
chen xu7ee67862018-10-30 22:27:10 -07006695 @Override
sqian65eefe12019-02-22 15:55:18 -08006696 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
sqian04b86072018-11-07 14:02:21 -08006697 String callingPackage) {
sqian03bca152018-12-05 18:48:28 -08006698 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
sqian65eefe12019-02-22 15:55:18 -08006699 mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) {
sqian03bca152018-12-05 18:48:28 -08006700 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6701 }
6702 final long identity = Binder.clearCallingIdentity();
6703 try {
sqian991b35e2018-12-12 16:48:18 -08006704 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
6705 for (Phone phone: PhoneFactory.getPhones()) {
6706 if (phone.getEmergencyNumberTracker() != null
6707 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
6708 emergencyNumberListInternal.put(
6709 phone.getSubId(),
6710 phone.getEmergencyNumberTracker().getEmergencyNumberList());
6711 }
sqian03bca152018-12-05 18:48:28 -08006712 }
sqian991b35e2018-12-12 16:48:18 -08006713 return emergencyNumberListInternal;
sqian03bca152018-12-05 18:48:28 -08006714 } finally {
6715 Binder.restoreCallingIdentity(identity);
6716 }
sqian04b86072018-11-07 14:02:21 -08006717 }
6718
6719 @Override
sqian65eefe12019-02-22 15:55:18 -08006720 public boolean isEmergencyNumber(String number, boolean exactMatch) {
sqian03bca152018-12-05 18:48:28 -08006721 final Phone defaultPhone = getDefaultPhone();
6722 if (!exactMatch) {
6723 TelephonyPermissions
6724 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian65eefe12019-02-22 15:55:18 -08006725 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian03bca152018-12-05 18:48:28 -08006726 }
6727 final long identity = Binder.clearCallingIdentity();
6728 try {
sqian991b35e2018-12-12 16:48:18 -08006729 for (Phone phone: PhoneFactory.getPhones()) {
6730 if (phone.getEmergencyNumberTracker() != null
6731 && phone.getEmergencyNumberTracker() != null) {
6732 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
6733 number, exactMatch)) {
6734 return true;
sqian03bca152018-12-05 18:48:28 -08006735 }
6736 }
sqian03bca152018-12-05 18:48:28 -08006737 }
6738 return false;
6739 } finally {
6740 Binder.restoreCallingIdentity(identity);
6741 }
6742 }
6743
sqian9d4df8b2019-01-15 18:32:07 -08006744 /**
6745 * Update emergency number list for test mode.
6746 */
6747 @Override
6748 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
6749 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6750 "updateEmergencyNumberListTestMode");
6751
6752 final long identity = Binder.clearCallingIdentity();
6753 try {
6754 for (Phone phone: PhoneFactory.getPhones()) {
6755 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6756 if (tracker != null) {
6757 tracker.executeEmergencyNumberTestModeCommand(action, num);
6758 }
6759 }
6760 } finally {
6761 Binder.restoreCallingIdentity(identity);
6762 }
6763 }
6764
6765 /**
6766 * Get the full emergency number list for test mode.
6767 */
6768 @Override
6769 public List<String> getEmergencyNumberListTestMode() {
6770 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6771 "getEmergencyNumberListTestMode");
6772
6773 final long identity = Binder.clearCallingIdentity();
6774 try {
6775 Set<String> emergencyNumbers = new HashSet<>();
6776 for (Phone phone: PhoneFactory.getPhones()) {
6777 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6778 if (tracker != null) {
6779 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
6780 emergencyNumbers.add(num.getNumber());
6781 }
6782 }
6783 }
6784 return new ArrayList<>(emergencyNumbers);
6785 } finally {
6786 Binder.restoreCallingIdentity(identity);
6787 }
6788 }
6789
sqian04b86072018-11-07 14:02:21 -08006790 @Override
chen xu7ee67862018-10-30 22:27:10 -07006791 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
6792 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
6793 Phone phone = getPhone(subId);
6794 if (phone == null) {
6795 return null;
6796 }
6797 final long identity = Binder.clearCallingIdentity();
6798 try {
6799 UiccProfile profile = UiccController.getInstance()
6800 .getUiccProfileForPhone(phone.getPhoneId());
6801 if (profile != null) {
6802 return profile.getCertsFromCarrierPrivilegeAccessRules();
6803 }
6804 } finally {
6805 Binder.restoreCallingIdentity(identity);
6806 }
6807 return null;
6808 }
Malcolm Chen509b5b72019-01-15 20:22:16 -08006809
6810 /**
6811 * Enable or disable a modem stack.
6812 */
6813 @Override
6814 public boolean enableModemForSlot(int slotIndex, boolean enable) {
6815 enforceModifyPermission();
6816
6817 final long identity = Binder.clearCallingIdentity();
6818 try {
6819 Phone phone = PhoneFactory.getPhone(slotIndex);
6820 if (phone == null) {
6821 return false;
6822 } else {
6823 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
6824 }
6825 } finally {
6826 Binder.restoreCallingIdentity(identity);
6827 }
6828 }
Micheled3107c52018-12-21 15:00:11 -08006829
Malcolm Chen33f55e12019-03-27 18:34:05 -07006830 /**
6831 * Whether a modem stack is enabled or not.
6832 */
6833 @Override
6834 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage) {
6835 Phone phone = PhoneFactory.getPhone(slotIndex);
6836 if (phone == null) return false;
6837
6838 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6839 mApp, phone.getSubId(), callingPackage, "isModemEnabledForSlot")) {
6840 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6841 }
6842
6843 final long identity = Binder.clearCallingIdentity();
6844 try {
Nazanin Bakhshi1f78d7d2019-04-29 17:29:44 -07006845 try {
6846 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
6847 } catch (NoSuchElementException ex) {
6848 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
6849 }
Malcolm Chen33f55e12019-03-27 18:34:05 -07006850 } finally {
6851 Binder.restoreCallingIdentity(identity);
6852 }
6853 }
6854
Micheled3107c52018-12-21 15:00:11 -08006855 @Override
Michele2fb0f222019-03-19 14:58:42 -07006856 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Micheled3107c52018-12-21 15:00:11 -08006857 enforceModifyPermission();
6858
6859 final long identity = Binder.clearCallingIdentity();
6860 try {
6861 mTelephonySharedPreferences.edit()
Michele2fb0f222019-03-19 14:58:42 -07006862 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Micheled3107c52018-12-21 15:00:11 -08006863 .commit();
6864 } finally {
6865 Binder.restoreCallingIdentity(identity);
6866 }
6867 }
6868
6869 @Override
Michele2fb0f222019-03-19 14:58:42 -07006870 @TelephonyManager.IsMultiSimSupportedResult
6871 public int isMultiSimSupported(String callingPackage) {
Michelebcb01bc2019-02-04 11:36:23 -08006872 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Michele2fb0f222019-03-19 14:58:42 -07006873 getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) {
6874 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michelebcb01bc2019-02-04 11:36:23 -08006875 }
Micheled3107c52018-12-21 15:00:11 -08006876
6877 final long identity = Binder.clearCallingIdentity();
6878 try {
Michele2fb0f222019-03-19 14:58:42 -07006879 return isMultiSimSupportedInternal();
Micheled3107c52018-12-21 15:00:11 -08006880 } finally {
6881 Binder.restoreCallingIdentity(identity);
6882 }
6883 }
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006884
Michele2fb0f222019-03-19 14:58:42 -07006885 @TelephonyManager.IsMultiSimSupportedResult
6886 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08006887 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
6888 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
6889 if (numPhysicalSlots < 2) {
Michele2fb0f222019-03-19 14:58:42 -07006890 loge("isMultiSimSupportedInternal: requires at least 2 cards");
6891 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006892 }
6893 // Check if the hardware supports multisim functionality. If usage of multisim is not
6894 // supported by the modem, indicate that it is restricted.
6895 PhoneCapability staticCapability =
6896 mPhoneConfigurationManager.getStaticPhoneCapability();
6897 if (staticCapability == null) {
Michele2fb0f222019-03-19 14:58:42 -07006898 loge("isMultiSimSupportedInternal: no static configuration available");
6899 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006900 }
6901 if (staticCapability.logicalModemList.size() < 2) {
Michele2fb0f222019-03-19 14:58:42 -07006902 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
6903 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006904 }
6905 // Check if support of multiple SIMs is restricted by carrier
6906 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele2fb0f222019-03-19 14:58:42 -07006907 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08006908 }
6909
Michele2fb0f222019-03-19 14:58:42 -07006910 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08006911 }
6912
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006913 /**
6914 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi814dc222019-03-01 11:56:08 -08006915 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
6916 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
6917 * or carrier privileges
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006918 * @param numOfSims number of active sims we want to switch to
6919 */
6920 @Override
6921 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi814dc222019-03-01 11:56:08 -08006922 if (numOfSims == 1) {
6923 enforceModifyPermission();
6924 } else {
6925 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6926 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
6927 }
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006928 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08006929
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006930 try {
Michele30b57b22019-03-01 12:01:14 -08006931 //only proceed if multi-sim is not restricted
Michele2fb0f222019-03-19 14:58:42 -07006932 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08006933 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
6934 return;
6935 }
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006936 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
6937 } finally {
6938 Binder.restoreCallingIdentity(identity);
6939 }
6940 }
6941
6942 /**
Nazanin Bakhshicd417af2019-01-30 10:52:09 -08006943 * Get whether reboot is required or not after making changes to modem configurations.
Nazanin Bakhshi4a68f5f2019-02-08 14:31:19 -08006944 * Return value defaults to true
Nazanin Bakhshicd417af2019-01-30 10:52:09 -08006945 */
6946 @Override
6947 public boolean isRebootRequiredForModemConfigChange() {
6948 enforceReadPrivilegedPermission("isRebootRequiredForModemConfigChange");
6949 final long identity = Binder.clearCallingIdentity();
6950 try {
6951 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
6952 } finally {
6953 Binder.restoreCallingIdentity(identity);
6954 }
6955 }
6956
Pengquan Meng92d253b2019-02-06 11:12:53 -08006957 private void updateModemStateMetrics() {
6958 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
6959 // TODO: check the state for each modem if the api is ready.
6960 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
6961 }
6962
Pengquan Meng3aceaec2019-01-23 11:16:29 -08006963 @Override
6964 public int[] getSlotsMapping() {
6965 enforceReadPrivilegedPermission("getSlotsMapping");
6966
6967 final long identity = Binder.clearCallingIdentity();
6968 try {
6969 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
6970 // All logical slots should have a mapping to a physical slot.
6971 int[] logicalSlotsMapping = new int[phoneCount];
6972 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
6973 for (int i = 0; i < slotInfos.length; i++) {
6974 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
6975 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
6976 }
6977 }
6978 return logicalSlotsMapping;
6979 } finally {
6980 Binder.restoreCallingIdentity(identity);
6981 }
6982 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08006983
6984 /**
6985 * Get the IRadio HAL Version
6986 */
6987 @Override
6988 public int getRadioHalVersion() {
6989 Phone phone = getDefaultPhone();
6990 if (phone == null) return -1;
6991 HalVersion hv = phone.getHalVersion();
6992 if (hv.equals(HalVersion.UNKNOWN)) return -1;
6993 return hv.major * 100 + hv.minor;
6994 }
Malcolm Chen460810d2019-04-10 18:25:07 -07006995
6996 /**
Malcolm Chen29739692019-04-18 13:51:02 -07006997 * Return whether data is enabled for certain APN type. This will tell if framework will accept
6998 * corresponding network requests on a subId.
6999 *
7000 * Data is enabled if:
Malcolm Chen460810d2019-04-10 18:25:07 -07007001 * 1) user data is turned on, or
Malcolm Chen29739692019-04-18 13:51:02 -07007002 * 2) APN is un-metered for this subscription, or
7003 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
7004 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on.
7005 *
7006 * @return whether data is allowed for a apn type.
7007 *
7008 * @hide
Malcolm Chen460810d2019-04-10 18:25:07 -07007009 */
7010 @Override
Malcolm Chen29739692019-04-18 13:51:02 -07007011 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Malcolm Chen460810d2019-04-10 18:25:07 -07007012 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Malcolm Chen29739692019-04-18 13:51:02 -07007013 mApp, subId, callingPackage, "isDataEnabledForApn")) {
7014 throw new SecurityException("Needs READ_PHONE_STATE for isDataEnabledForApn");
Malcolm Chen460810d2019-04-10 18:25:07 -07007015 }
7016
7017 // Now that all security checks passes, perform the operation as ourselves.
7018 final long identity = Binder.clearCallingIdentity();
7019 try {
7020 Phone phone = getPhone(subId);
7021 if (phone == null) return false;
7022
Jack Yu40306fc2019-05-13 16:54:09 -07007023 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chen29739692019-04-18 13:51:02 -07007024 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7025 } finally {
7026 Binder.restoreCallingIdentity(identity);
7027 }
7028 }
7029
7030 @Override
Jack Yu40306fc2019-05-13 16:54:09 -07007031 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chen29739692019-04-18 13:51:02 -07007032 enforceReadPrivilegedPermission("isApnMetered");
7033
7034 // Now that all security checks passes, perform the operation as ourselves.
7035 final long identity = Binder.clearCallingIdentity();
7036 try {
7037 Phone phone = getPhone(subId);
7038 if (phone == null) return true; // By default return true.
7039
Jack Yu40306fc2019-05-13 16:54:09 -07007040 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chen460810d2019-04-10 18:25:07 -07007041 } finally {
7042 Binder.restoreCallingIdentity(identity);
7043 }
7044 }
chen xu7bc8e072019-05-28 15:20:57 -07007045
7046 @Override
Brad Ebinger5ff97f62019-04-23 16:31:13 -07007047 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
7048 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
7049 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
7050 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
7051 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
7052 }
7053 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
7054 Intent intent = new Intent();
7055 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
7056 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7057 // Bring up choose default SMS subscription dialog right now
7058 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
7059 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
7060 mApp.startActivity(intent);
7061 }
7062
7063 @Override
chen xu7bc8e072019-05-28 15:20:57 -07007064 public String getMmsUAProfUrl(int subId) {
7065 //TODO investigate if this API should require proper permission check in R b/133791609
7066 final long identity = Binder.clearCallingIdentity();
7067 try {
7068 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7069 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
7070 } finally {
7071 Binder.restoreCallingIdentity(identity);
7072 }
7073 }
7074
7075 @Override
7076 public String getMmsUserAgent(int subId) {
7077 //TODO investigate if this API should require proper permission check in R b/133791609
7078 final long identity = Binder.clearCallingIdentity();
7079 try {
7080 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7081 .getString(com.android.internal.R.string.config_mms_user_agent);
7082 } finally {
7083 Binder.restoreCallingIdentity(identity);
7084 }
7085 }
Jack Yuea3bebe2019-05-28 16:12:25 -07007086
7087 @Override
7088 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
7089 enforceModifyPermission();
7090
7091 // Now that all security checks passes, perform the operation as ourselves.
7092 final long identity = Binder.clearCallingIdentity();
7093 try {
7094 Phone phone = getPhone(subId);
7095 if (phone == null) return false;
7096
7097 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
7098 } finally {
7099 Binder.restoreCallingIdentity(identity);
7100 }
7101 }
7102
7103 @Override
7104 public boolean isDataAllowedInVoiceCall(int subId) {
7105 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
7106
7107 // Now that all security checks passes, perform the operation as ourselves.
7108 final long identity = Binder.clearCallingIdentity();
7109 try {
7110 Phone phone = getPhone(subId);
7111 if (phone == null) return false;
7112
7113 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
7114 } finally {
7115 Binder.restoreCallingIdentity(identity);
7116 }
7117 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007118}