blob: d0eda12f4240d154f42a131010a0ebde895ff6f6 [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
Tyler Gunn7bcdc742019-10-04 15:56:59 -070021import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070022import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
23
Ta-wei Yen30a69c82016-12-27 14:52:32 -080024import android.Manifest.permission;
Tyler Gunnf70ed162019-04-03 15:28:53 -070025import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070026import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080027import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070028import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070029import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070030import android.content.Context;
31import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070032import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070033import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070034import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080035import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070036import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070037import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070038import android.net.Uri;
39import android.os.AsyncResult;
40import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080041import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070042import android.os.Bundle;
43import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070044import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070045import android.os.Looper;
46import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070047import android.os.Messenger;
Tyler Gunn65d45c22017-06-05 11:22:26 -070048import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080049import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070050import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070051import android.os.ServiceManager;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070052import android.os.ServiceSpecificException;
Brad Ebingerdac2f002018-04-03 15:17:52 -070053import android.os.ShellCallback;
Pengquan Meng85728fb2018-03-12 16:31:21 -070054import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070056import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070057import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070058import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080059import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070060import android.provider.Telephony;
Santos Cordon7a1885b2015-02-03 11:15:19 -080061import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080062import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070063import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070064import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080065import android.telephony.CarrierRestrictionRules;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070066import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070067import android.telephony.CellInfoGsm;
68import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070069import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070070import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070071import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070072import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080073import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070074import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080075import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070076import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080077import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080078import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070079import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080080import android.telephony.RadioAccessSpecifier;
Tyler Gunn65d45c22017-06-05 11:22:26 -070081import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070082import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080083import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080084import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080085import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070086import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070087import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080088import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080089import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000090import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070091import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070092import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070093import android.telephony.cdma.CdmaCellLocation;
Jack Yub5d8f642018-11-26 11:20:48 -080094import android.telephony.data.ApnSetting;
Jack Yu41407ee2019-05-13 16:54:09 -070095import android.telephony.data.ApnSetting.ApnType;
Jack Yub5d8f642018-11-26 11:20:48 -080096import android.telephony.emergency.EmergencyNumber;
Nathan Harold3ff88932018-08-14 10:19:49 -070097import android.telephony.gsm.GsmCellLocation;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070098import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -080099import android.telephony.ims.ProvisioningManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700100import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800101import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700102import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800103import android.telephony.ims.aidl.IImsMmTelFeature;
104import android.telephony.ims.aidl.IImsRcsFeature;
105import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700106import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800107import android.telephony.ims.feature.MmTelFeature;
108import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800109import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700110import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800111import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700112import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800113import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800114import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800115
Andrew Lee312e8172014-10-23 17:01:36 -0700116import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800117import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700118import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700119import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700120import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800121import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700122import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700123import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700124import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800125import com.android.internal.telephony.HalVersion;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700126import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800127import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700128import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800129import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700130import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100131import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700132import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700133import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700134import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700135import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800136import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700137import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700138import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700139import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700140import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700141import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700142import com.android.internal.telephony.ServiceStateTracker;
Makoto Onukida3bf792018-09-18 16:06:29 -0700143import com.android.internal.telephony.SmsApplication;
144import com.android.internal.telephony.SmsApplication.SmsApplicationData;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700145import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700146import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800147import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800148import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700149import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800150import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700151import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800152import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700153import com.android.internal.telephony.imsphone.ImsPhone;
154import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800155import com.android.internal.telephony.metrics.TelephonyMetrics;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700156import com.android.internal.telephony.uicc.IccIoResult;
157import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800158import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700159import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800160import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700161import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800162import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000163import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700164import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800165import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700166import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700167import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800168import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700169import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700170import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800171
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700172import java.io.FileDescriptor;
173import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700174import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800175import java.util.Arrays;
Makoto Onukida3bf792018-09-18 16:06:29 -0700176import java.util.Collection;
sqian11b7a0e2018-12-05 18:48:28 -0800177import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800178import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800179import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100180import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800181import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700182import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800183import java.util.Set;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700184
185/**
186 * Implementation of the ITelephony interface.
187 */
Santos Cordon117fee72014-05-16 17:56:12 -0700188public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700189 private static final String LOG_TAG = "PhoneInterfaceManager";
190 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
191 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800192 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700193
194 // Message codes used with mMainThreadHandler
195 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700196 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
197 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700198 private static final int CMD_OPEN_CHANNEL = 9;
199 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
200 private static final int CMD_CLOSE_CHANNEL = 11;
201 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800202 private static final int CMD_NV_READ_ITEM = 13;
203 private static final int EVENT_NV_READ_ITEM_DONE = 14;
204 private static final int CMD_NV_WRITE_ITEM = 15;
205 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
206 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
207 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700208 private static final int CMD_RESET_MODEM_CONFIG = 19;
209 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800210 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
211 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
212 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
213 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800214 private static final int CMD_SEND_ENVELOPE = 25;
215 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000216 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
217 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700218 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
219 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
220 private static final int CMD_EXCHANGE_SIM_IO = 31;
221 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800222 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
223 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700224 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
225 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700226 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
227 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700228 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
229 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
230 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
231 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700232 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
233 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
234 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
235 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700236 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800237 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
238 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000239 private static final int CMD_SWITCH_SLOTS = 50;
240 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700241 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
242 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
243 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
244 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
245 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
246 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
247 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
248 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700249 private static final int CMD_GET_ALL_CELL_INFO = 60;
250 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
251 private static final int CMD_GET_CELL_LOCATION = 62;
252 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700253 private static final int CMD_MODEM_REBOOT = 64;
254 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700255 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
256 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800257 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
258 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700259 private static final int CMD_GET_MODEM_STATUS = 70;
260 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700261
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800262 // Parameters of select command.
263 private static final int SELECT_COMMAND = 0xA4;
264 private static final int SELECT_P1 = 0x04;
265 private static final int SELECT_P2 = 0;
266 private static final int SELECT_P3 = 0x10;
267
Pengquan Meng85728fb2018-03-12 16:31:21 -0700268 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
269 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
270 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
271
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700272 /** The singleton instance. */
273 private static PhoneInterfaceManager sInstance;
274
Wink Saville3ab207e2014-11-20 13:07:20 -0800275 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800276 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700277 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800278 private AppOpsManager mAppOps;
279 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800280 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800281 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700282 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700283
Derek Tan97ebb422014-09-05 16:55:38 -0700284 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
285 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800286 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800287 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700288
Michelecea4cf22018-12-21 15:00:11 -0800289 // String to store multi SIM allowed
290 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
291
Derek Tan740e1672017-06-27 14:56:27 -0700292 // The AID of ISD-R.
293 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
294
yinxub1bed742017-04-17 11:45:04 -0700295 private NetworkScanRequestTracker mNetworkScanRequestTracker;
296
David Kelly5e06a7f2018-03-12 14:10:59 +0000297 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
298 private static final int MANUFACTURER_CODE_LENGTH = 8;
299
Derek Tan89e89d42014-07-08 17:00:10 -0700300 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700301 * A request object to use for transmitting data to an ICC.
302 */
303 private static final class IccAPDUArgument {
304 public int channel, cla, command, p1, p2, p3;
305 public String data;
306
307 public IccAPDUArgument(int channel, int cla, int command,
308 int p1, int p2, int p3, String data) {
309 this.channel = channel;
310 this.cla = cla;
311 this.command = command;
312 this.p1 = p1;
313 this.p2 = p2;
314 this.p3 = p3;
315 this.data = data;
316 }
317 }
318
319 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700320 * A request object to use for transmitting data to an ICC.
321 */
322 private static final class ManualNetworkSelectionArgument {
323 public OperatorInfo operatorInfo;
324 public boolean persistSelection;
325
326 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
327 this.operatorInfo = operatorInfo;
328 this.persistSelection = persistSelection;
329 }
330 }
331
332 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700333 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
334 * request after sending. The main thread will notify the request when it is complete.
335 */
336 private static final class MainThreadRequest {
337 /** The argument to use for the request */
338 public Object argument;
339 /** The result of the request that is run on the main thread */
340 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800341 // The subscriber id that this request applies to. Defaults to
342 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
343 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700344
Nathan Harold92bed182018-10-12 18:16:49 -0700345 // In cases where subId is unavailable, the caller needs to specify the phone.
346 public Phone phone;
347
vagdeviaf9a5b92018-08-15 16:01:53 -0700348 public WorkSource workSource;
349
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700350 public MainThreadRequest(Object argument) {
351 this.argument = argument;
352 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800353
Nathan Harold92bed182018-10-12 18:16:49 -0700354 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
355 this.argument = argument;
356 if (phone != null) {
357 this.phone = phone;
358 }
359 this.workSource = workSource;
360 }
361
vagdeviaf9a5b92018-08-15 16:01:53 -0700362 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800363 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800364 if (subId != null) {
365 this.subId = subId;
366 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700367 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800368 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700369 }
370
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800371 private static final class IncomingThirdPartyCallArgs {
372 public final ComponentName component;
373 public final String callId;
374 public final String callerDisplayName;
375
376 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
377 String callerDisplayName) {
378 this.component = component;
379 this.callId = callId;
380 this.callerDisplayName = callerDisplayName;
381 }
382 }
383
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700384 /**
385 * A handler that processes messages on the main thread in the phone process. Since many
386 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
387 * inbound binder threads to the main thread in the phone process. The Binder thread
388 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
389 * on, which will be notified when the operation completes and will contain the result of the
390 * request.
391 *
392 * <p>If a MainThreadRequest object is provided in the msg.obj field,
393 * note that request.result must be set to something non-null for the calling thread to
394 * unblock.
395 */
396 private final class MainThreadHandler extends Handler {
397 @Override
398 public void handleMessage(Message msg) {
399 MainThreadRequest request;
400 Message onCompleted;
401 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800402 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700403 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800404 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700405
406 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700407 case CMD_HANDLE_USSD_REQUEST: {
408 request = (MainThreadRequest) msg.obj;
409 final Phone phone = getPhoneFromRequest(request);
410 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
411 String ussdRequest = ussdObject.first;
412 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700413
Pengquan Menga1bb6272018-09-06 09:59:22 -0700414 if (!isUssdApiAllowed(request.subId)) {
415 // Carrier does not support use of this API, return failure.
416 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
417 UssdResponse response = new UssdResponse(ussdRequest, null);
418 Bundle returnData = new Bundle();
419 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
420 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700421
Pengquan Menga1bb6272018-09-06 09:59:22 -0700422 request.result = true;
423 notifyRequester(request);
424 return;
425 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700426
Pengquan Menga1bb6272018-09-06 09:59:22 -0700427 try {
428 request.result = phone != null
429 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
430 } catch (CallStateException cse) {
431 request.result = false;
432 }
433 // Wake up the requesting thread
434 notifyRequester(request);
435 break;
pkanwar32d516d2016-10-14 19:37:38 -0700436 }
437
Yorke Lee716f67e2015-06-17 15:39:16 -0700438 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700439 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700440 final Phone phone = getPhoneFromRequest(request);
441 request.result = phone != null ?
442 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
443 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700444 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700445 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700446 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700447 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700448
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700449 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700450 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700451 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800452 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700453 if (uiccCard == null) {
454 loge("iccTransmitApduLogicalChannel: No UICC");
455 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700456 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700457 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700458 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
459 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700460 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700461 iccArgument.channel, iccArgument.cla, iccArgument.command,
462 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700463 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700464 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700465 break;
466
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700467 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700468 ar = (AsyncResult) msg.obj;
469 request = (MainThreadRequest) ar.userObj;
470 if (ar.exception == null && ar.result != null) {
471 request.result = ar.result;
472 } else {
473 request.result = new IccIoResult(0x6F, 0, (byte[])null);
474 if (ar.result == null) {
475 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800476 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700477 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800478 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700479 } else {
480 loge("iccTransmitApduLogicalChannel: Unknown exception");
481 }
482 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700483 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700484 break;
485
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700486 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
487 request = (MainThreadRequest) msg.obj;
488 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800489 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700490 if (uiccCard == null) {
491 loge("iccTransmitApduBasicChannel: No UICC");
492 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700493 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700494 } else {
495 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
496 request);
497 uiccCard.iccTransmitApduBasicChannel(
498 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
499 iccArgument.p3, iccArgument.data, onCompleted);
500 }
501 break;
502
503 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
504 ar = (AsyncResult) msg.obj;
505 request = (MainThreadRequest) ar.userObj;
506 if (ar.exception == null && ar.result != null) {
507 request.result = ar.result;
508 } else {
509 request.result = new IccIoResult(0x6F, 0, (byte[])null);
510 if (ar.result == null) {
511 loge("iccTransmitApduBasicChannel: Empty response");
512 } else if (ar.exception instanceof CommandException) {
513 loge("iccTransmitApduBasicChannel: CommandException: " +
514 ar.exception);
515 } else {
516 loge("iccTransmitApduBasicChannel: Unknown exception");
517 }
518 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700519 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700520 break;
521
522 case CMD_EXCHANGE_SIM_IO:
523 request = (MainThreadRequest) msg.obj;
524 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800525 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700526 if (uiccCard == null) {
527 loge("iccExchangeSimIO: No UICC");
528 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700529 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700530 } else {
531 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
532 request);
533 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
534 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
535 iccArgument.data, onCompleted);
536 }
537 break;
538
539 case EVENT_EXCHANGE_SIM_IO_DONE:
540 ar = (AsyncResult) msg.obj;
541 request = (MainThreadRequest) ar.userObj;
542 if (ar.exception == null && ar.result != null) {
543 request.result = ar.result;
544 } else {
545 request.result = new IccIoResult(0x6f, 0, (byte[])null);
546 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700547 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700548 break;
549
Derek Tan4d5e5c12014-02-04 11:54:58 -0800550 case CMD_SEND_ENVELOPE:
551 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800552 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700553 if (uiccCard == null) {
554 loge("sendEnvelopeWithStatus: No UICC");
555 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700556 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700557 } else {
558 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
559 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
560 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800561 break;
562
563 case EVENT_SEND_ENVELOPE_DONE:
564 ar = (AsyncResult) msg.obj;
565 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700566 if (ar.exception == null && ar.result != null) {
567 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800568 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700569 request.result = new IccIoResult(0x6F, 0, (byte[])null);
570 if (ar.result == null) {
571 loge("sendEnvelopeWithStatus: Empty response");
572 } else if (ar.exception instanceof CommandException) {
573 loge("sendEnvelopeWithStatus: CommandException: " +
574 ar.exception);
575 } else {
576 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
577 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800578 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700579 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800580 break;
581
Shishir Agrawal566b7612013-10-28 14:41:00 -0700582 case CMD_OPEN_CHANNEL:
583 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800584 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800585 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700586 if (uiccCard == null) {
587 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800588 request.result = new IccOpenLogicalChannelResponse(-1,
589 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700590 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700591 } else {
592 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800593 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
594 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700595 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700596 break;
597
598 case EVENT_OPEN_CHANNEL_DONE:
599 ar = (AsyncResult) msg.obj;
600 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700601 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700602 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700603 int[] result = (int[]) ar.result;
604 int channelId = result[0];
605 byte[] selectResponse = null;
606 if (result.length > 1) {
607 selectResponse = new byte[result.length - 1];
608 for (int i = 1; i < result.length; ++i) {
609 selectResponse[i - 1] = (byte) result[i];
610 }
611 }
612 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700613 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700614 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700615 if (ar.result == null) {
616 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700617 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700618 if (ar.exception != null) {
619 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
620 }
621
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700622 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700623 if (ar.exception instanceof CommandException) {
624 CommandException.Error error =
625 ((CommandException) (ar.exception)).getCommandError();
626 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700627 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700628 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700629 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700630 }
631 }
632 openChannelResp = new IccOpenLogicalChannelResponse(
633 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700634 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700635 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700636 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700637 break;
638
639 case CMD_CLOSE_CHANNEL:
640 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800641 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700642 if (uiccCard == null) {
643 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900644 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700645 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700646 } else {
647 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
648 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
649 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700650 break;
651
652 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800653 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
654 break;
655
656 case CMD_NV_READ_ITEM:
657 request = (MainThreadRequest) msg.obj;
658 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800659 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
660 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800661 break;
662
663 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700664 ar = (AsyncResult) msg.obj;
665 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800666 if (ar.exception == null && ar.result != null) {
667 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700668 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800669 request.result = "";
670 if (ar.result == null) {
671 loge("nvReadItem: Empty response");
672 } else if (ar.exception instanceof CommandException) {
673 loge("nvReadItem: CommandException: " +
674 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700675 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800676 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700677 }
678 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700679 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700680 break;
681
Jake Hambye994d462014-02-03 13:10:13 -0800682 case CMD_NV_WRITE_ITEM:
683 request = (MainThreadRequest) msg.obj;
684 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
685 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800686 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700687 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800688 break;
689
690 case EVENT_NV_WRITE_ITEM_DONE:
691 handleNullReturnEvent(msg, "nvWriteItem");
692 break;
693
694 case CMD_NV_WRITE_CDMA_PRL:
695 request = (MainThreadRequest) msg.obj;
696 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800697 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800698 break;
699
700 case EVENT_NV_WRITE_CDMA_PRL_DONE:
701 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
702 break;
703
chen xu6dac5ab2018-10-26 17:39:23 -0700704 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800705 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700706 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800707 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800708 break;
709
chen xu6dac5ab2018-10-26 17:39:23 -0700710 case EVENT_RESET_MODEM_CONFIG_DONE:
711 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800712 break;
713
Jake Hamby7c27be32014-03-03 13:25:59 -0800714 case CMD_GET_PREFERRED_NETWORK_TYPE:
715 request = (MainThreadRequest) msg.obj;
716 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700717 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800718 break;
719
720 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
721 ar = (AsyncResult) msg.obj;
722 request = (MainThreadRequest) ar.userObj;
723 if (ar.exception == null && ar.result != null) {
724 request.result = ar.result; // Integer
725 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800726 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800727 if (ar.result == null) {
728 loge("getPreferredNetworkType: Empty response");
729 } else if (ar.exception instanceof CommandException) {
730 loge("getPreferredNetworkType: CommandException: " +
731 ar.exception);
732 } else {
733 loge("getPreferredNetworkType: Unknown exception");
734 }
735 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700736 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800737 break;
738
739 case CMD_SET_PREFERRED_NETWORK_TYPE:
740 request = (MainThreadRequest) msg.obj;
741 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
742 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700743 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800744 break;
745
746 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
747 handleNullReturnEvent(msg, "setPreferredNetworkType");
748 break;
749
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000750 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
751 request = (MainThreadRequest)msg.obj;
752 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800753 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000754 break;
755
756 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
757 ar = (AsyncResult)msg.obj;
758 request = (MainThreadRequest)ar.userObj;
759 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700760 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000761 break;
762
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800763 case CMD_SET_VOICEMAIL_NUMBER:
764 request = (MainThreadRequest) msg.obj;
765 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
766 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800767 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
768 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800769 break;
770
771 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
772 handleNullReturnEvent(msg, "setVoicemailNumber");
773 break;
774
Stuart Scott54788802015-03-30 13:18:01 -0700775 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
776 request = (MainThreadRequest) msg.obj;
777 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
778 request);
779 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
780 break;
781
782 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
783 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
784 break;
785
Shishir Agrawal302c8692015-06-19 13:49:39 -0700786 case CMD_PERFORM_NETWORK_SCAN:
787 request = (MainThreadRequest) msg.obj;
788 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
789 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
790 break;
791
792 case EVENT_PERFORM_NETWORK_SCAN_DONE:
793 ar = (AsyncResult) msg.obj;
794 request = (MainThreadRequest) ar.userObj;
795 CellNetworkScanResult cellScanResult;
796 if (ar.exception == null && ar.result != null) {
797 cellScanResult = new CellNetworkScanResult(
798 CellNetworkScanResult.STATUS_SUCCESS,
799 (List<OperatorInfo>) ar.result);
800 } else {
801 if (ar.result == null) {
802 loge("getCellNetworkScanResults: Empty response");
803 }
804 if (ar.exception != null) {
805 loge("getCellNetworkScanResults: Exception: " + ar.exception);
806 }
807 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
808 if (ar.exception instanceof CommandException) {
809 CommandException.Error error =
810 ((CommandException) (ar.exception)).getCommandError();
811 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
812 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
813 } else if (error == CommandException.Error.GENERIC_FAILURE) {
814 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
815 }
816 }
817 cellScanResult = new CellNetworkScanResult(errorCode, null);
818 }
819 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700820 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700821 break;
822
823 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
824 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700825 ManualNetworkSelectionArgument selArg =
826 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700827 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
828 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700829 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
830 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700831 break;
832
833 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700834 ar = (AsyncResult) msg.obj;
835 request = (MainThreadRequest) ar.userObj;
836 if (ar.exception == null) {
837 request.result = true;
838 } else {
839 request.result = false;
840 loge("setNetworkSelectionModeManual " + ar.exception);
841 }
842 notifyRequester(request);
843 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700844 break;
845
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700846 case CMD_GET_MODEM_ACTIVITY_INFO:
847 request = (MainThreadRequest) msg.obj;
848 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -0700849 if (defaultPhone != null) {
850 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
851 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700852 break;
853
854 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
855 ar = (AsyncResult) msg.obj;
856 request = (MainThreadRequest) ar.userObj;
857 if (ar.exception == null && ar.result != null) {
858 request.result = ar.result;
859 } else {
860 if (ar.result == null) {
861 loge("queryModemActivityInfo: Empty response");
862 } else if (ar.exception instanceof CommandException) {
863 loge("queryModemActivityInfo: CommandException: " +
864 ar.exception);
865 } else {
866 loge("queryModemActivityInfo: Unknown exception");
867 }
868 }
Amit Mahajand4766222016-01-28 15:28:28 -0800869 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
870 if (request.result == null) {
871 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
872 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700873 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700874 break;
875
Meng Wang1a7c35a2016-05-05 20:56:15 -0700876 case CMD_SET_ALLOWED_CARRIERS:
877 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -0800878 CarrierRestrictionRules argument =
879 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700880 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -0800881 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700882 break;
883
884 case EVENT_SET_ALLOWED_CARRIERS_DONE:
885 ar = (AsyncResult) msg.obj;
886 request = (MainThreadRequest) ar.userObj;
887 if (ar.exception == null && ar.result != null) {
888 request.result = ar.result;
889 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800890 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
891 if (ar.exception instanceof CommandException) {
892 loge("setAllowedCarriers: CommandException: " + ar.exception);
893 CommandException.Error error =
894 ((CommandException) (ar.exception)).getCommandError();
895 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
896 request.result =
897 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
898 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700899 } else {
900 loge("setAllowedCarriers: Unknown exception");
901 }
902 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700903 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700904 break;
905
906 case CMD_GET_ALLOWED_CARRIERS:
907 request = (MainThreadRequest) msg.obj;
908 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800909 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700910 break;
911
912 case EVENT_GET_ALLOWED_CARRIERS_DONE:
913 ar = (AsyncResult) msg.obj;
914 request = (MainThreadRequest) ar.userObj;
915 if (ar.exception == null && ar.result != null) {
916 request.result = ar.result;
917 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800918 request.result = new IllegalStateException(
919 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700920 if (ar.result == null) {
921 loge("getAllowedCarriers: Empty response");
922 } else if (ar.exception instanceof CommandException) {
923 loge("getAllowedCarriers: CommandException: " +
924 ar.exception);
925 } else {
926 loge("getAllowedCarriers: Unknown exception");
927 }
928 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700929 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700930 break;
931
Nathan Haroldb3014052017-01-25 15:57:32 -0800932 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
933 ar = (AsyncResult) msg.obj;
934 request = (MainThreadRequest) ar.userObj;
935 if (ar.exception == null && ar.result != null) {
936 request.result = ar.result;
937 } else {
938 request.result = new IllegalArgumentException(
939 "Failed to retrieve Forbidden Plmns");
940 if (ar.result == null) {
941 loge("getForbiddenPlmns: Empty response");
942 } else {
943 loge("getForbiddenPlmns: Unknown exception");
944 }
945 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700946 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800947 break;
948
949 case CMD_GET_FORBIDDEN_PLMNS:
950 request = (MainThreadRequest) msg.obj;
951 uiccCard = getUiccCardFromRequest(request);
952 if (uiccCard == null) {
953 loge("getForbiddenPlmns() UiccCard is null");
954 request.result = new IllegalArgumentException(
955 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700956 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800957 break;
958 }
959 Integer appType = (Integer) request.argument;
960 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
961 if (uiccApp == null) {
962 loge("getForbiddenPlmns() no app with specified type -- "
963 + appType);
964 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700965 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800966 break;
967 } else {
968 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
969 + " specified type -- " + appType);
970 }
971 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
972 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
973 onCompleted);
974 break;
975
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000976 case CMD_SWITCH_SLOTS:
977 request = (MainThreadRequest) msg.obj;
978 int[] physicalSlots = (int[]) request.argument;
979 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
980 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
981 break;
982
983 case EVENT_SWITCH_SLOTS_DONE:
984 ar = (AsyncResult) msg.obj;
985 request = (MainThreadRequest) ar.userObj;
986 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700987 notifyRequester(request);
988 break;
989 case CMD_GET_NETWORK_SELECTION_MODE:
990 request = (MainThreadRequest) msg.obj;
991 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
992 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
993 break;
994
995 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
996 ar = (AsyncResult) msg.obj;
997 request = (MainThreadRequest) ar.userObj;
998 if (ar.exception != null) {
999 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1000 } else {
1001 int mode = ((int[]) ar.result)[0];
1002 if (mode == 0) {
1003 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1004 } else {
1005 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1006 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001007 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001008 notifyRequester(request);
1009 break;
1010 case CMD_GET_CDMA_ROAMING_MODE:
1011 request = (MainThreadRequest) msg.obj;
1012 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1013 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1014 break;
1015 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1016 ar = (AsyncResult) msg.obj;
1017 request = (MainThreadRequest) ar.userObj;
1018 if (ar.exception != null) {
1019 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1020 } else {
1021 request.result = ((int[]) ar.result)[0];
1022 }
1023 notifyRequester(request);
1024 break;
1025 case CMD_SET_CDMA_ROAMING_MODE:
1026 request = (MainThreadRequest) msg.obj;
1027 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1028 int mode = (int) request.argument;
1029 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1030 break;
1031 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1032 ar = (AsyncResult) msg.obj;
1033 request = (MainThreadRequest) ar.userObj;
1034 request.result = ar.exception == null;
1035 notifyRequester(request);
1036 break;
1037 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1038 request = (MainThreadRequest) msg.obj;
1039 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1040 int subscriptionMode = (int) request.argument;
1041 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1042 break;
1043 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1044 ar = (AsyncResult) msg.obj;
1045 request = (MainThreadRequest) ar.userObj;
1046 request.result = ar.exception == null;
1047 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001048 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001049 case CMD_GET_ALL_CELL_INFO:
1050 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001051 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001052 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001053 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001054 case EVENT_GET_ALL_CELL_INFO_DONE:
1055 ar = (AsyncResult) msg.obj;
1056 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001057 // If a timeout occurs, the response will be null
1058 request.result = (ar.exception == null && ar.result != null)
1059 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001060 synchronized (request) {
1061 request.notifyAll();
1062 }
1063 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001064 case CMD_REQUEST_CELL_INFO_UPDATE:
1065 request = (MainThreadRequest) msg.obj;
1066 request.phone.requestCellInfoUpdate(request.workSource,
1067 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1068 break;
1069 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1070 ar = (AsyncResult) msg.obj;
1071 request = (MainThreadRequest) ar.userObj;
1072 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1073 try {
1074 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001075 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Nathan Harolde82c4b82018-12-18 19:40:37 -08001076 cb.onError(TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1077 new android.os.ParcelableException(ar.exception));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001078 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001079 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Nathan Harolde82c4b82018-12-18 19:40:37 -08001080 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001081 } else {
1082 // use the result as returned
1083 cb.onCellInfo((List<CellInfo>) ar.result);
1084 }
1085 } catch (RemoteException re) {
1086 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1087 }
1088 break;
1089 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001090 request = (MainThreadRequest) msg.obj;
1091 WorkSource ws = (WorkSource) request.argument;
1092 Phone phone = getPhoneFromRequest(request);
1093 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1094 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001095 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001096 ar = (AsyncResult) msg.obj;
1097 request = (MainThreadRequest) ar.userObj;
1098 if (ar.exception == null) {
1099 request.result = ar.result;
1100 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001101 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001102 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1103 ? new CdmaCellLocation() : new GsmCellLocation();
1104 }
1105
1106 synchronized (request) {
1107 request.notifyAll();
1108 }
1109 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001110 case CMD_MODEM_REBOOT:
1111 request = (MainThreadRequest) msg.obj;
1112 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001113 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001114 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001115 case EVENT_CMD_MODEM_REBOOT_DONE:
1116 handleNullReturnEvent(msg, "rebootModem");
1117 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001118 case CMD_REQUEST_ENABLE_MODEM:
1119 request = (MainThreadRequest) msg.obj;
1120 boolean enable = (boolean) request.argument;
1121 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001122 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001123 PhoneConfigurationManager.getInstance()
1124 .enablePhone(request.phone, enable, onCompleted);
1125 break;
1126 case EVENT_ENABLE_MODEM_DONE:
1127 ar = (AsyncResult) msg.obj;
1128 request = (MainThreadRequest) ar.userObj;
1129 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001130 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001131 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001132 if ((boolean) request.result) {
1133 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1134 updateModemStateMetrics();
1135 } else {
1136 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1137 + ar.exception);
1138 }
1139 notifyRequester(request);
1140 break;
1141 case CMD_GET_MODEM_STATUS:
1142 request = (MainThreadRequest) msg.obj;
1143 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1144 PhoneConfigurationManager.getInstance()
1145 .getPhoneStatusFromModem(request.phone, onCompleted);
1146 break;
1147 case EVENT_GET_MODEM_STATUS_DONE:
1148 ar = (AsyncResult) msg.obj;
1149 request = (MainThreadRequest) ar.userObj;
1150 int id = request.phone.getPhoneId();
1151 if (ar.exception == null && ar.result != null) {
1152 request.result = ar.result;
1153 //update the cache as modem status has changed
1154 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1155 (boolean) request.result);
1156 } else {
1157 // Return true if modem status cannot be retrieved. For most cases,
1158 // modem status is on. And for older version modems, GET_MODEM_STATUS
1159 // and disable modem are not supported. Modem is always on.
1160 // TODO: this should be fixed in R to support a third
1161 // status UNKNOWN b/131631629
1162 request.result = true;
1163 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1164 + ar.exception);
1165 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001166 notifyRequester(request);
1167 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001168 default:
1169 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1170 break;
1171 }
1172 }
Jake Hambye994d462014-02-03 13:10:13 -08001173
Pengquan Menga1bb6272018-09-06 09:59:22 -07001174 private void notifyRequester(MainThreadRequest request) {
1175 synchronized (request) {
1176 request.notifyAll();
1177 }
1178 }
1179
Jake Hambye994d462014-02-03 13:10:13 -08001180 private void handleNullReturnEvent(Message msg, String command) {
1181 AsyncResult ar = (AsyncResult) msg.obj;
1182 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1183 if (ar.exception == null) {
1184 request.result = true;
1185 } else {
1186 request.result = false;
1187 if (ar.exception instanceof CommandException) {
1188 loge(command + ": CommandException: " + ar.exception);
1189 } else {
1190 loge(command + ": Unknown exception");
1191 }
1192 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001193 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001194 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001195 }
1196
1197 /**
1198 * Posts the specified command to be executed on the main thread,
1199 * waits for the request to complete, and returns the result.
1200 * @see #sendRequestAsync
1201 */
1202 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001203 return sendRequest(
1204 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001205 }
1206
1207 /**
1208 * Posts the specified command to be executed on the main thread,
1209 * waits for the request to complete, and returns the result.
1210 * @see #sendRequestAsync
1211 */
1212 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1213 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001214 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001215 }
1216
1217 /**
1218 * Posts the specified command to be executed on the main thread,
1219 * waits for the request to complete, and returns the result.
1220 * @see #sendRequestAsync
1221 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001222 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001223 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001224 }
1225
1226 /**
1227 * Posts the specified command to be executed on the main thread,
1228 * waits for the request to complete, and returns the result.
1229 * @see #sendRequestAsync
1230 */
Nathan Harold92bed182018-10-12 18:16:49 -07001231 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1232 return sendRequest(command, argument, subId, null, workSource);
1233 }
1234
1235 /**
1236 * Posts the specified command to be executed on the main thread,
1237 * waits for the request to complete, and returns the result.
1238 * @see #sendRequestAsync
1239 */
1240 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1241 return sendRequest(
1242 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1243 }
1244
1245 /**
1246 * Posts the specified command to be executed on the main thread,
1247 * waits for the request to complete, and returns the result.
1248 * @see #sendRequestAsync
1249 */
1250 private Object sendRequest(
1251 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001252 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1253 throw new RuntimeException("This method will deadlock if called from the main thread.");
1254 }
1255
Nathan Harold92bed182018-10-12 18:16:49 -07001256 MainThreadRequest request = null;
1257 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1258 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1259 } else if (phone != null) {
1260 request = new MainThreadRequest(argument, phone, workSource);
1261 } else {
1262 request = new MainThreadRequest(argument, subId, workSource);
1263 }
1264
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001265 Message msg = mMainThreadHandler.obtainMessage(command, request);
1266 msg.sendToTarget();
1267
1268 // Wait for the request to complete
1269 synchronized (request) {
1270 while (request.result == null) {
1271 try {
1272 request.wait();
1273 } catch (InterruptedException e) {
1274 // Do nothing, go back and wait until the request is complete
1275 }
1276 }
1277 }
1278 return request.result;
1279 }
1280
1281 /**
1282 * Asynchronous ("fire and forget") version of sendRequest():
1283 * Posts the specified command to be executed on the main thread, and
1284 * returns immediately.
1285 * @see #sendRequest
1286 */
1287 private void sendRequestAsync(int command) {
1288 mMainThreadHandler.sendEmptyMessage(command);
1289 }
1290
1291 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001292 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001293 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001294 */
1295 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001296 sendRequestAsync(command, argument, null, null);
1297 }
1298
1299 /**
1300 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1301 * @see {@link #sendRequest(int,Object)}
1302 */
1303 private void sendRequestAsync(
1304 int command, Object argument, Phone phone, WorkSource workSource) {
1305 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001306 Message msg = mMainThreadHandler.obtainMessage(command, request);
1307 msg.sendToTarget();
1308 }
1309
1310 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001311 * Initialize the singleton PhoneInterfaceManager instance.
1312 * This is only done once, at startup, from PhoneApp.onCreate().
1313 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001314 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001315 synchronized (PhoneInterfaceManager.class) {
1316 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001317 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001318 } else {
1319 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1320 }
1321 return sInstance;
1322 }
1323 }
1324
1325 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001326 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001327 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001328 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001329 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001330 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1331 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001332 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001333 mTelephonySharedPreferences =
1334 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001335 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001336 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001337
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001338 publish();
1339 }
1340
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001341 private Phone getDefaultPhone() {
1342 Phone thePhone = getPhone(getDefaultSubscription());
1343 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1344 }
1345
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001346 private void publish() {
1347 if (DBG) log("publish: " + this);
1348
1349 ServiceManager.addService("phone", this);
1350 }
1351
Stuart Scott584921c2015-01-15 17:10:34 -08001352 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001353 if (request.phone != null) {
1354 return request.phone;
1355 } else {
1356 return getPhoneFromSubId(request.subId);
1357 }
1358 }
1359
1360 private Phone getPhoneFromSubId(int subId) {
1361 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1362 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001363 }
1364
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001365 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1366 Phone phone = getPhoneFromRequest(request);
1367 return phone == null ? null :
1368 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1369 }
1370
Wink Saville36469e72014-06-11 15:17:00 -07001371 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001372 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001373 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001374 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001375
1376 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001377 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001378 }
1379
Wink Savilleb564aae2014-10-23 10:18:09 -07001380 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001381 if (DBG) log("dial: " + number);
1382 // No permission check needed here: This is just a wrapper around the
1383 // ACTION_DIAL intent, which is available to any app since it puts up
1384 // the UI before it does anything.
1385
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001386 final long identity = Binder.clearCallingIdentity();
1387 try {
1388 String url = createTelUrl(number);
1389 if (url == null) {
1390 return;
1391 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001392
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001393 // PENDING: should we just silently fail if phone is offhook or ringing?
1394 PhoneConstants.State state = mCM.getState(subId);
1395 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1396 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1397 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1398 mApp.startActivity(intent);
1399 }
1400 } finally {
1401 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001402 }
1403 }
1404
1405 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001406 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001407 }
1408
Wink Savilleb564aae2014-10-23 10:18:09 -07001409 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001410 if (DBG) log("call: " + number);
1411
1412 // This is just a wrapper around the ACTION_CALL intent, but we still
1413 // need to do a permission check since we're calling startActivity()
1414 // from the context of the phone app.
1415 enforceCallPermission();
1416
Jordan Liu1617b712019-07-10 15:06:26 -07001417 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001418 != AppOpsManager.MODE_ALLOWED) {
1419 return;
1420 }
1421
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001422 final long identity = Binder.clearCallingIdentity();
1423 try {
1424 String url = createTelUrl(number);
1425 if (url == null) {
1426 return;
1427 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001428
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001429 boolean isValid = false;
1430 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1431 if (slist != null) {
1432 for (SubscriptionInfo subInfoRecord : slist) {
1433 if (subInfoRecord.getSubscriptionId() == subId) {
1434 isValid = true;
1435 break;
1436 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001437 }
Wink Saville08874612014-08-31 19:19:58 -07001438 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001439 if (!isValid) {
1440 return;
1441 }
Wink Saville08874612014-08-31 19:19:58 -07001442
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001443 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1444 intent.putExtra(SUBSCRIPTION_KEY, subId);
1445 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1446 mApp.startActivity(intent);
1447 } finally {
1448 Binder.restoreCallingIdentity(identity);
1449 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001450 }
1451
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001452 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001453 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001454 }
1455
Wink Savilleb564aae2014-10-23 10:18:09 -07001456 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001457 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001458 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1459 }
1460
1461 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001462 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001463 }
1464
Wink Savilleb564aae2014-10-23 10:18:09 -07001465 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001466 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001467 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1468 }
1469
1470 /** {@hide} */
1471 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001472 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001473 }
1474
Wink Savilleb564aae2014-10-23 10:18:09 -07001475 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001476 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001477
1478 final long identity = Binder.clearCallingIdentity();
1479 try {
1480 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1481 checkSimPin.start();
1482 return checkSimPin.unlockSim(null, pin);
1483 } finally {
1484 Binder.restoreCallingIdentity(identity);
1485 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001486 }
1487
Wink Saville9de0f752013-10-22 19:04:03 -07001488 /** {@hide} */
1489 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001490 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001491 }
1492
Wink Savilleb564aae2014-10-23 10:18:09 -07001493 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001494 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001495
1496 final long identity = Binder.clearCallingIdentity();
1497 try {
1498 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1499 checkSimPuk.start();
1500 return checkSimPuk.unlockSim(puk, pin);
1501 } finally {
1502 Binder.restoreCallingIdentity(identity);
1503 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001504 }
1505
1506 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001507 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001508 * a synchronous one.
1509 */
1510 private static class UnlockSim extends Thread {
1511
1512 private final IccCard mSimCard;
1513
1514 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001515 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1516 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001517
1518 // For replies from SimCard interface
1519 private Handler mHandler;
1520
1521 // For async handler to identify request type
1522 private static final int SUPPLY_PIN_COMPLETE = 100;
1523
1524 public UnlockSim(IccCard simCard) {
1525 mSimCard = simCard;
1526 }
1527
1528 @Override
1529 public void run() {
1530 Looper.prepare();
1531 synchronized (UnlockSim.this) {
1532 mHandler = new Handler() {
1533 @Override
1534 public void handleMessage(Message msg) {
1535 AsyncResult ar = (AsyncResult) msg.obj;
1536 switch (msg.what) {
1537 case SUPPLY_PIN_COMPLETE:
1538 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1539 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001540 mRetryCount = msg.arg1;
1541 if (ar.exception != null) {
1542 if (ar.exception instanceof CommandException &&
1543 ((CommandException)(ar.exception)).getCommandError()
1544 == CommandException.Error.PASSWORD_INCORRECT) {
1545 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1546 } else {
1547 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1548 }
1549 } else {
1550 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1551 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001552 mDone = true;
1553 UnlockSim.this.notifyAll();
1554 }
1555 break;
1556 }
1557 }
1558 };
1559 UnlockSim.this.notifyAll();
1560 }
1561 Looper.loop();
1562 }
1563
1564 /*
1565 * Use PIN or PUK to unlock SIM card
1566 *
1567 * If PUK is null, unlock SIM card with PIN
1568 *
1569 * If PUK is not null, unlock SIM card with PUK and set PIN code
1570 */
Wink Saville9de0f752013-10-22 19:04:03 -07001571 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001572
1573 while (mHandler == null) {
1574 try {
1575 wait();
1576 } catch (InterruptedException e) {
1577 Thread.currentThread().interrupt();
1578 }
1579 }
1580 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1581
1582 if (puk == null) {
1583 mSimCard.supplyPin(pin, callback);
1584 } else {
1585 mSimCard.supplyPuk(puk, pin, callback);
1586 }
1587
1588 while (!mDone) {
1589 try {
1590 Log.d(LOG_TAG, "wait for done");
1591 wait();
1592 } catch (InterruptedException e) {
1593 // Restore the interrupted status
1594 Thread.currentThread().interrupt();
1595 }
1596 }
1597 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001598 int[] resultArray = new int[2];
1599 resultArray[0] = mResult;
1600 resultArray[1] = mRetryCount;
1601 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001602 }
1603 }
1604
1605 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001606 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001607
1608 }
1609
Wink Savilleb564aae2014-10-23 10:18:09 -07001610 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001611 // No permission check needed here: this call is harmless, and it's
1612 // needed for the ServiceState.requestStateUpdate() call (which is
1613 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001614 final long identity = Binder.clearCallingIdentity();
1615 try {
1616 final Phone phone = getPhone(subId);
1617 if (phone != null) {
1618 phone.updateServiceLocation();
1619 }
1620 } finally {
1621 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001622 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001623 }
1624
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001625 @Override
1626 public boolean isRadioOn(String callingPackage) {
1627 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001628 }
1629
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001630 @Override
1631 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001632 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001633 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001634 return false;
1635 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001636
1637 final long identity = Binder.clearCallingIdentity();
1638 try {
1639 return isRadioOnForSubscriber(subId);
1640 } finally {
1641 Binder.restoreCallingIdentity(identity);
1642 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001643 }
1644
1645 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001646 final long identity = Binder.clearCallingIdentity();
1647 try {
1648 final Phone phone = getPhone(subId);
1649 if (phone != null) {
1650 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1651 } else {
1652 return false;
1653 }
1654 } finally {
1655 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001656 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001657 }
1658
1659 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001660 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001661 }
Wink Saville36469e72014-06-11 15:17:00 -07001662
Wink Savilleb564aae2014-10-23 10:18:09 -07001663 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001664 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001665
1666 final long identity = Binder.clearCallingIdentity();
1667 try {
1668 final Phone phone = getPhone(subId);
1669 if (phone != null) {
1670 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1671 }
1672 } finally {
1673 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001674 }
Wink Saville36469e72014-06-11 15:17:00 -07001675 }
1676
1677 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001678 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001679 }
1680
Wink Savilleb564aae2014-10-23 10:18:09 -07001681 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001682 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001683
1684 final long identity = Binder.clearCallingIdentity();
1685 try {
1686 final Phone phone = getPhone(subId);
1687 if (phone == null) {
1688 return false;
1689 }
1690 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1691 toggleRadioOnOffForSubscriber(subId);
1692 }
1693 return true;
1694 } finally {
1695 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001696 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001697 }
Wink Saville36469e72014-06-11 15:17:00 -07001698
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001699 public boolean needMobileRadioShutdown() {
1700 /*
1701 * If any of the Radios are available, it will need to be
1702 * shutdown. So return true if any Radio is available.
1703 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001704 final long identity = Binder.clearCallingIdentity();
1705 try {
1706 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1707 Phone phone = PhoneFactory.getPhone(i);
1708 if (phone != null && phone.isRadioAvailable()) return true;
1709 }
1710 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1711 return false;
1712 } finally {
1713 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001714 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001715 }
1716
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001717 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001718 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001719 enforceModifyPermission();
1720
1721 final long identity = Binder.clearCallingIdentity();
1722 try {
1723 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1724 logv("Shutting down Phone " + i);
1725 shutdownRadioUsingPhoneId(i);
1726 }
1727 } finally {
1728 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001729 }
1730 }
1731
1732 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001733 Phone phone = PhoneFactory.getPhone(phoneId);
1734 if (phone != null && phone.isRadioAvailable()) {
1735 phone.shutdownRadio();
1736 }
1737 }
1738
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001739 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001740 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001741
1742 final long identity = Binder.clearCallingIdentity();
1743 try {
1744 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1745 if (defaultPhone != null) {
1746 defaultPhone.setRadioPower(turnOn);
1747 return true;
1748 } else {
1749 loge("There's no default phone.");
1750 return false;
1751 }
1752 } finally {
1753 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001754 }
Wink Saville36469e72014-06-11 15:17:00 -07001755 }
1756
Wink Savilleb564aae2014-10-23 10:18:09 -07001757 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001758 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001759
1760 final long identity = Binder.clearCallingIdentity();
1761 try {
1762 final Phone phone = getPhone(subId);
1763 if (phone != null) {
1764 phone.setRadioPower(turnOn);
1765 return true;
1766 } else {
1767 return false;
1768 }
1769 } finally {
1770 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001771 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001772 }
1773
Wink Saville36469e72014-06-11 15:17:00 -07001774 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001775 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001776 public boolean enableDataConnectivity() {
1777 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001778
1779 final long identity = Binder.clearCallingIdentity();
1780 try {
1781 int subId = mSubscriptionController.getDefaultDataSubId();
1782 final Phone phone = getPhone(subId);
1783 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001784 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001785 return true;
1786 } else {
1787 return false;
1788 }
1789 } finally {
1790 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001791 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001792 }
1793
Wink Saville36469e72014-06-11 15:17:00 -07001794 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001795 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001796 public boolean disableDataConnectivity() {
1797 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001798
1799 final long identity = Binder.clearCallingIdentity();
1800 try {
1801 int subId = mSubscriptionController.getDefaultDataSubId();
1802 final Phone phone = getPhone(subId);
1803 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001804 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001805 return true;
1806 } else {
1807 return false;
1808 }
1809 } finally {
1810 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001811 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001812 }
1813
Sanket Padawe356d7632015-06-22 14:03:32 -07001814 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001815 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001816 final long identity = Binder.clearCallingIdentity();
1817 try {
1818 final Phone phone = getPhone(subId);
1819 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001820 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001821 } else {
1822 return false;
1823 }
1824 } finally {
1825 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001826 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001827 }
1828
1829 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001830 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001831 }
1832
pkanwarae03a6b2016-11-06 20:37:09 -08001833 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001834 enforceCallPermission();
1835
1836 final long identity = Binder.clearCallingIdentity();
1837 try {
1838 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1839 return;
1840 }
1841 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1842 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1843 } finally {
1844 Binder.restoreCallingIdentity(identity);
1845 }
pkanwar32d516d2016-10-14 19:37:38 -07001846 };
1847
Wink Savilleb564aae2014-10-23 10:18:09 -07001848 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001849 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001850
1851 final long identity = Binder.clearCallingIdentity();
1852 try {
1853 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1854 return false;
1855 }
1856 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1857 } finally {
1858 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001859 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001860 }
1861
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001862 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001863 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001864 }
1865
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001866 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001867 final long identity = Binder.clearCallingIdentity();
1868 try {
1869 Phone phone = PhoneFactory.getPhone(slotIndex);
1870 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1871 PhoneConstantConversions.convertCallState(phone.getState());
1872 } finally {
1873 Binder.restoreCallingIdentity(identity);
1874 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001875 }
1876
Sanket Padawe356d7632015-06-22 14:03:32 -07001877 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001878 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001879 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
1880 }
1881
1882 @Override
1883 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001884 final long identity = Binder.clearCallingIdentity();
1885 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001886 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001887 if (phone != null) {
1888 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1889 } else {
1890 return PhoneConstantConversions.convertDataState(
1891 PhoneConstants.DataState.DISCONNECTED);
1892 }
1893 } finally {
1894 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001895 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001896 }
1897
Sanket Padawe356d7632015-06-22 14:03:32 -07001898 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001899 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001900 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
1901 }
1902
1903 @Override
1904 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001905 final long identity = Binder.clearCallingIdentity();
1906 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001907 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001908 if (phone != null) {
1909 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1910 } else {
1911 return TelephonyManager.DATA_ACTIVITY_NONE;
1912 }
1913 } finally {
1914 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001915 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001916 }
1917
1918 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001919 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001920 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001921 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08001922
1923 LocationAccessPolicy.LocationPermissionResult locationResult =
1924 LocationAccessPolicy.checkLocationPermission(mApp,
1925 new LocationAccessPolicy.LocationPermissionQuery.Builder()
1926 .setCallingPackage(callingPackage)
1927 .setCallingPid(Binder.getCallingPid())
1928 .setCallingUid(Binder.getCallingUid())
1929 .setMethod("getCellLocation")
1930 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
1931 .build());
1932 switch (locationResult) {
1933 case DENIED_HARD:
1934 throw new SecurityException("Not allowed to access cell location");
1935 case DENIED_SOFT:
1936 return new Bundle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001937 }
1938
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001939 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001940 final long identity = Binder.clearCallingIdentity();
1941 try {
1942 if (DBG_LOC) log("getCellLocation: is active user");
1943 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001944 int subId = mSubscriptionController.getDefaultDataSubId();
1945 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1946 cl.fillInNotifierBundle(data);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001947 return data;
1948 } finally {
1949 Binder.restoreCallingIdentity(identity);
1950 }
Svetoslav64fad262015-04-14 14:35:21 -07001951 }
1952
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001953 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001954 public String getNetworkCountryIsoForPhone(int phoneId) {
1955 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1956 // registered cell info, so return a NULL country instead.
1957 final long identity = Binder.clearCallingIdentity();
1958 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001959 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1960 // Get default phone in this case.
1961 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1962 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001963 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001964 // Todo: fix this when we can get the actual cellular network info when the device
1965 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001966 if (TelephonyManager.NETWORK_TYPE_IWLAN
1967 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1968 return "";
1969 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001970 Phone phone = PhoneFactory.getPhone(phoneId);
1971 if (phone != null) {
1972 ServiceStateTracker sst = phone.getServiceStateTracker();
sqian1c069d02019-07-31 20:23:45 -07001973 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001974 if (sst != null) {
1975 LocaleTracker lt = sst.getLocaleTracker();
1976 if (lt != null) {
sqian1c069d02019-07-31 20:23:45 -07001977 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
1978 return lt.getCurrentCountry();
1979 } else if (emergencyNumberTracker != null) {
1980 return emergencyNumberTracker.getEmergencyCountryIso();
1981 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001982 }
1983 }
1984 }
1985 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001986 } finally {
1987 Binder.restoreCallingIdentity(identity);
1988 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001989 }
1990
1991 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001992 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001993 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001994 }
1995
Sanket Padawe356d7632015-06-22 14:03:32 -07001996 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001997 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001998 mApp.enforceCallingOrSelfPermission(
1999 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002000
2001 final long identity = Binder.clearCallingIdentity();
2002 try {
2003 final Phone phone = getPhone(subId);
2004 if (phone != null) {
2005 phone.enableLocationUpdates();
2006 }
2007 } finally {
2008 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002009 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002010 }
2011
2012 @Override
2013 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002014 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002015 }
2016
Sanket Padawe356d7632015-06-22 14:03:32 -07002017 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002018 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002019 mApp.enforceCallingOrSelfPermission(
2020 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002021
2022 final long identity = Binder.clearCallingIdentity();
2023 try {
2024 final Phone phone = getPhone(subId);
2025 if (phone != null) {
2026 phone.disableLocationUpdates();
2027 }
2028 } finally {
2029 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002030 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002031 }
2032
Nathan Harold31d7ff32018-10-15 20:20:30 -07002033 /**
2034 * Returns the target SDK version number for a given package name.
2035 *
Nathan Haroldec184742019-07-10 17:04:16 -07002036 * This call MUST be invoked before clearing the calling UID.
2037 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002038 * @return target SDK if the package is found or INT_MAX.
2039 */
2040 private int getTargetSdk(String packageName) {
2041 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002042 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
2043 packageName, 0, UserHandle.getUserId(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002044 if (ai != null) return ai.targetSdkVersion;
2045 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002046 loge("Failed to get package info for pkg="
2047 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002048 }
2049 return Integer.MAX_VALUE;
2050 }
2051
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002052 @Override
2053 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07002054 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
2055 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002056 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2057 throw new SecurityException(
2058 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2059 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002060
Jordan Liu1617b712019-07-10 15:06:26 -07002061 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002062 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2063 return null;
2064 }
Svetoslav64fad262015-04-14 14:35:21 -07002065
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002066 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002067
Nathan Haroldf180aac2018-06-01 18:43:55 -07002068 List<CellInfo> info = getAllCellInfo(callingPackage);
2069 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002070
Nathan Haroldf180aac2018-06-01 18:43:55 -07002071 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2072 for (CellInfo ci : info) {
2073 if (ci instanceof CellInfoGsm) {
2074 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2075 } else if (ci instanceof CellInfoWcdma) {
2076 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2077 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002078 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002079 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002080 }
2081
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002082 private List<CellInfo> getCachedCellInfo() {
2083 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2084 for (Phone phone : PhoneFactory.getPhones()) {
2085 List<CellInfo> info = phone.getAllCellInfo();
2086 if (info != null) cellInfos.addAll(info);
2087 }
2088 return cellInfos;
2089 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002090
2091 @Override
Svetoslav64fad262015-04-14 14:35:21 -07002092 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002093 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002094 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002095
2096 LocationAccessPolicy.LocationPermissionResult locationResult =
2097 LocationAccessPolicy.checkLocationPermission(mApp,
2098 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2099 .setCallingPackage(callingPackage)
2100 .setCallingPid(Binder.getCallingPid())
2101 .setCallingUid(Binder.getCallingUid())
2102 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002103 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002104 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2105 .build());
2106 switch (locationResult) {
2107 case DENIED_HARD:
2108 throw new SecurityException("Not allowed to access cell info");
2109 case DENIED_SOFT:
2110 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002111 }
2112
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002113 final int targetSdk = getTargetSdk(callingPackage);
2114 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2115 return getCachedCellInfo();
2116 }
2117
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002118 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002119 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002120 final long identity = Binder.clearCallingIdentity();
2121 try {
2122 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2123 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002124 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002125 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002126 if (info != null) cellInfos.addAll(info);
2127 }
2128 return cellInfos;
2129 } finally {
2130 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002131 }
2132 }
2133
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002134 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002135 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2136 requestCellInfoUpdateInternal(
2137 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2138 }
2139
2140 @Override
2141 public void requestCellInfoUpdateWithWorkSource(
2142 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2143 enforceModifyPermission();
2144 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2145 }
2146
2147 private void requestCellInfoUpdateInternal(
2148 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002149 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002150 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002151
2152 LocationAccessPolicy.LocationPermissionResult locationResult =
2153 LocationAccessPolicy.checkLocationPermission(mApp,
2154 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2155 .setCallingPackage(callingPackage)
2156 .setCallingPid(Binder.getCallingPid())
2157 .setCallingUid(Binder.getCallingUid())
2158 .setMethod("requestCellInfoUpdate")
2159 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2160 .build());
2161 switch (locationResult) {
2162 case DENIED_HARD:
2163 throw new SecurityException("Not allowed to access cell info");
2164 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002165 try {
2166 cb.onCellInfo(new ArrayList<CellInfo>());
2167 } catch (RemoteException re) {
2168 // Drop without consequences
2169 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002170 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002171 }
2172
Nathan Harolda939a962019-05-09 10:13:47 -07002173
2174 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002175 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2176
2177 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2178 }
2179
2180 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002181 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002182 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002183 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002184
2185 final long identity = Binder.clearCallingIdentity();
2186 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002187 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002188 } finally {
2189 Binder.restoreCallingIdentity(identity);
2190 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002191 }
2192
Shishir Agrawala9f32182016-04-12 12:00:16 -07002193 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002194 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002195 Phone phone = PhoneFactory.getPhone(slotIndex);
2196 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002197 return null;
2198 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002199 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002200 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2201 callingPackage, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002202 return null;
2203 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002204
2205 final long identity = Binder.clearCallingIdentity();
2206 try {
2207 return phone.getImei();
2208 } finally {
2209 Binder.restoreCallingIdentity(identity);
2210 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002211 }
2212
2213 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002214 public String getTypeAllocationCodeForSlot(int slotIndex) {
2215 Phone phone = PhoneFactory.getPhone(slotIndex);
2216 String tac = null;
2217 if (phone != null) {
2218 String imei = phone.getImei();
2219 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2220 }
2221 return tac;
2222 }
2223
2224 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002225 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002226 Phone phone = PhoneFactory.getPhone(slotIndex);
2227 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002228 return null;
2229 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002230
Jeff Davidson913390f2018-02-23 17:11:49 -08002231 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002232 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2233 callingPackage, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002234 return null;
2235 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002236
2237 final long identity = Binder.clearCallingIdentity();
2238 try {
2239 return phone.getMeid();
2240 } finally {
2241 Binder.restoreCallingIdentity(identity);
2242 }
Jack Yu2af8d712017-03-15 17:14:14 -07002243 }
2244
2245 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002246 public String getManufacturerCodeForSlot(int slotIndex) {
2247 Phone phone = PhoneFactory.getPhone(slotIndex);
2248 String manufacturerCode = null;
2249 if (phone != null) {
2250 String meid = phone.getMeid();
2251 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2252 }
2253 return manufacturerCode;
2254 }
2255
2256 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002257 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002258 Phone phone = PhoneFactory.getPhone(slotIndex);
2259 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002260 return null;
2261 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002262 int subId = phone.getSubId();
2263 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2264 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2265 return null;
2266 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002267
2268 final long identity = Binder.clearCallingIdentity();
2269 try {
2270 return phone.getDeviceSvn();
2271 } finally {
2272 Binder.restoreCallingIdentity(identity);
2273 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002274 }
2275
fionaxu43304da2017-11-27 22:51:16 -08002276 @Override
2277 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002278 final long identity = Binder.clearCallingIdentity();
2279 try {
2280 final Phone phone = getPhone(subId);
2281 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2282 } finally {
2283 Binder.restoreCallingIdentity(identity);
2284 }
fionaxu43304da2017-11-27 22:51:16 -08002285 }
2286
2287 @Override
2288 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002289 final long identity = Binder.clearCallingIdentity();
2290 try {
2291 final Phone phone = getPhone(subId);
2292 return phone == null ? null : phone.getCarrierName();
2293 } finally {
2294 Binder.restoreCallingIdentity(identity);
2295 }
fionaxu43304da2017-11-27 22:51:16 -08002296 }
2297
calvinpanffe225e2018-11-01 19:43:06 +08002298 @Override
chen xu0026ca62019-03-06 15:28:50 -08002299 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002300 final long identity = Binder.clearCallingIdentity();
2301 try {
2302 final Phone phone = getPhone(subId);
2303 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002304 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002305 } finally {
2306 Binder.restoreCallingIdentity(identity);
2307 }
2308 }
2309
2310 @Override
chen xu0026ca62019-03-06 15:28:50 -08002311 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002312 final long identity = Binder.clearCallingIdentity();
2313 try {
2314 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002315 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002316 } finally {
2317 Binder.restoreCallingIdentity(identity);
2318 }
2319 }
2320
chen xu651eec72018-11-11 19:03:44 -08002321 @Override
chen xu864e11c2018-12-06 22:10:03 -08002322 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2323 if (!isSubscriptionMccMnc) {
2324 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2325 }
chen xu651eec72018-11-11 19:03:44 -08002326 final Phone phone = PhoneFactory.getPhone(slotIndex);
2327 if (phone == null) {
2328 return TelephonyManager.UNKNOWN_CARRIER_ID;
2329 }
2330 final long identity = Binder.clearCallingIdentity();
2331 try {
2332 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2333 } finally {
2334 Binder.restoreCallingIdentity(identity);
2335 }
2336 }
2337
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002338 //
2339 // Internal helper methods.
2340 //
2341
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002342 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002343 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2344 *
2345 * @throws SecurityException if the caller does not have the required permission
2346 */
2347 private void enforceModifyPermission() {
2348 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2349 }
2350
2351 /**
2352 * Make sure the caller has the CALL_PHONE permission.
2353 *
2354 * @throws SecurityException if the caller does not have the required permission
2355 */
2356 private void enforceCallPermission() {
2357 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2358 }
2359
Stuart Scott8eef64f2015-04-08 15:13:54 -07002360 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002361 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002362 "ConnectivityService");
2363 }
2364
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002365 private String createTelUrl(String number) {
2366 if (TextUtils.isEmpty(number)) {
2367 return null;
2368 }
2369
Jake Hambye994d462014-02-03 13:10:13 -08002370 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002371 }
2372
Ihab Awadf9e92732013-12-05 18:02:52 -08002373 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002374 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2375 }
2376
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002377 private static void logv(String msg) {
2378 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2379 }
2380
Ihab Awadf9e92732013-12-05 18:02:52 -08002381 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002382 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2383 }
2384
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002385 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002386 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002387 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002388 }
2389
Sanket Padawe356d7632015-06-22 14:03:32 -07002390 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002391 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002392 final long identity = Binder.clearCallingIdentity();
2393 try {
2394 final Phone phone = PhoneFactory.getPhone(slotIndex);
2395 if (phone == null) {
2396 return PhoneConstants.PHONE_TYPE_NONE;
2397 } else {
2398 return phone.getPhoneType();
2399 }
2400 } finally {
2401 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002402 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002403 }
2404
2405 /**
2406 * Returns the CDMA ERI icon index to display
2407 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002408 @Override
2409 public int getCdmaEriIconIndex(String callingPackage) {
2410 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002411 }
2412
Sanket Padawe356d7632015-06-22 14:03:32 -07002413 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002414 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002415 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002416 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002417 return -1;
2418 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002419
2420 final long identity = Binder.clearCallingIdentity();
2421 try {
2422 final Phone phone = getPhone(subId);
2423 if (phone != null) {
2424 return phone.getCdmaEriIconIndex();
2425 } else {
2426 return -1;
2427 }
2428 } finally {
2429 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002430 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002431 }
2432
2433 /**
2434 * Returns the CDMA ERI icon mode,
2435 * 0 - ON
2436 * 1 - FLASHING
2437 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002438 @Override
2439 public int getCdmaEriIconMode(String callingPackage) {
2440 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002441 }
2442
Sanket Padawe356d7632015-06-22 14:03:32 -07002443 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002444 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002445 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002446 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002447 return -1;
2448 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002449
2450 final long identity = Binder.clearCallingIdentity();
2451 try {
2452 final Phone phone = getPhone(subId);
2453 if (phone != null) {
2454 return phone.getCdmaEriIconMode();
2455 } else {
2456 return -1;
2457 }
2458 } finally {
2459 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002460 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002461 }
2462
2463 /**
2464 * Returns the CDMA ERI text,
2465 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002466 @Override
2467 public String getCdmaEriText(String callingPackage) {
2468 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002469 }
2470
Sanket Padawe356d7632015-06-22 14:03:32 -07002471 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002472 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002473 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002474 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002475 return null;
2476 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002477
2478 final long identity = Binder.clearCallingIdentity();
2479 try {
2480 final Phone phone = getPhone(subId);
2481 if (phone != null) {
2482 return phone.getCdmaEriText();
2483 } else {
2484 return null;
2485 }
2486 } finally {
2487 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002488 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002489 }
2490
2491 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002492 * Returns the CDMA MDN.
2493 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002494 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002495 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002496 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2497 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002498
2499 final long identity = Binder.clearCallingIdentity();
2500 try {
2501 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002502 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002503 return phone.getLine1Number();
2504 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002505 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002506 return null;
2507 }
2508 } finally {
2509 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002510 }
2511 }
2512
2513 /**
2514 * Returns the CDMA MIN.
2515 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002516 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002517 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002518 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2519 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002520
2521 final long identity = Binder.clearCallingIdentity();
2522 try {
2523 final Phone phone = getPhone(subId);
2524 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2525 return phone.getCdmaMin();
2526 } else {
2527 return null;
2528 }
2529 } finally {
2530 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002531 }
2532 }
2533
Hall Liud892bec2018-11-30 14:51:45 -08002534 @Override
2535 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2536 INumberVerificationCallback callback, String callingPackage) {
2537 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2538 != PERMISSION_GRANTED) {
2539 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2540 }
2541 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2542
2543 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2544 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2545 throw new SecurityException("Calling package must be configured in the device config");
2546 }
2547
2548 if (range == null) {
2549 throw new NullPointerException("Range must be non-null");
2550 }
2551
2552 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002553 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002554
2555 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2556 }
2557
Junda Liuca05d5d2014-08-14 22:36:34 -07002558 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002559 * Returns true if CDMA provisioning needs to run.
2560 */
2561 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002562 final long identity = Binder.clearCallingIdentity();
2563 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002564 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002565 } finally {
2566 Binder.restoreCallingIdentity(identity);
2567 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002568 }
2569
2570 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002571 * Sets the voice mail number of a given subId.
2572 */
2573 @Override
2574 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002575 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002576
2577 final long identity = Binder.clearCallingIdentity();
2578 try {
2579 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2580 new Pair<String, String>(alphaTag, number), new Integer(subId));
2581 return success;
2582 } finally {
2583 Binder.restoreCallingIdentity(identity);
2584 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002585 }
2586
Ta-wei Yen87c49842016-05-13 21:19:52 -07002587 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002588 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2589 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002590 String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002591 if (!TextUtils.equals(callingPackage, systemDialer)) {
2592 throw new SecurityException("caller must be system dialer");
2593 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002594
2595 final long identity = Binder.clearCallingIdentity();
2596 try {
2597 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2598 if (phoneAccountHandle == null) {
2599 return null;
2600 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002601 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002602 } finally {
2603 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002604 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002605 }
2606
2607 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002608 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002609 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002610 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002611 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002612 return null;
2613 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002614
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002615 final long identity = Binder.clearCallingIdentity();
2616 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002617 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002618 } finally {
2619 Binder.restoreCallingIdentity(identity);
2620 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002621 }
2622
2623 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002624 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2625 VisualVoicemailSmsFilterSettings settings) {
2626 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002627
2628 final long identity = Binder.clearCallingIdentity();
2629 try {
2630 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002631 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002632 } finally {
2633 Binder.restoreCallingIdentity(identity);
2634 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002635 }
2636
2637 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002638 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2639 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002640
2641 final long identity = Binder.clearCallingIdentity();
2642 try {
2643 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002644 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002645 } finally {
2646 Binder.restoreCallingIdentity(identity);
2647 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002648 }
2649
2650 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002651 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2652 String callingPackage, int subId) {
2653 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002654
2655 final long identity = Binder.clearCallingIdentity();
2656 try {
2657 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002658 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002659 } finally {
2660 Binder.restoreCallingIdentity(identity);
2661 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002662 }
2663
2664 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002665 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002666 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002667
2668 final long identity = Binder.clearCallingIdentity();
2669 try {
2670 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002671 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002672 } finally {
2673 Binder.restoreCallingIdentity(identity);
2674 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002675 }
2676
2677 @Override
2678 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2679 String number, int port, String text, PendingIntent sentIntent) {
2680 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002681 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002682 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07002683 SmsController smsController = PhoneFactory.getSmsController();
2684 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
2685 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002686 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07002687
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002688 /**
fionaxu0152e512016-11-14 13:36:14 -08002689 * Sets the voice activation state of a given subId.
2690 */
2691 @Override
2692 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002693 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2694 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002695
2696 final long identity = Binder.clearCallingIdentity();
2697 try {
2698 final Phone phone = getPhone(subId);
2699 if (phone != null) {
2700 phone.setVoiceActivationState(activationState);
2701 } else {
2702 loge("setVoiceActivationState fails with invalid subId: " + subId);
2703 }
2704 } finally {
2705 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002706 }
2707 }
2708
2709 /**
2710 * Sets the data activation state of a given subId.
2711 */
2712 @Override
2713 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002714 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2715 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002716
2717 final long identity = Binder.clearCallingIdentity();
2718 try {
2719 final Phone phone = getPhone(subId);
2720 if (phone != null) {
2721 phone.setDataActivationState(activationState);
2722 } else {
2723 loge("setVoiceActivationState fails with invalid subId: " + subId);
2724 }
2725 } finally {
2726 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002727 }
2728 }
2729
2730 /**
2731 * Returns the voice activation state of a given subId.
2732 */
2733 @Override
2734 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002735 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002736
fionaxu0152e512016-11-14 13:36:14 -08002737 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002738 final long identity = Binder.clearCallingIdentity();
2739 try {
2740 if (phone != null) {
2741 return phone.getVoiceActivationState();
2742 } else {
2743 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2744 }
2745 } finally {
2746 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002747 }
2748 }
2749
2750 /**
2751 * Returns the data activation state of a given subId.
2752 */
2753 @Override
2754 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002755 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002756
fionaxu0152e512016-11-14 13:36:14 -08002757 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002758 final long identity = Binder.clearCallingIdentity();
2759 try {
2760 if (phone != null) {
2761 return phone.getDataActivationState();
2762 } else {
2763 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2764 }
2765 } finally {
2766 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002767 }
2768 }
2769
2770 /**
Wink Saville36469e72014-06-11 15:17:00 -07002771 * Returns the unread count of voicemails for a subId
2772 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002773 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002774 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2775 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2776 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2777 return 0;
2778 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002779 final long identity = Binder.clearCallingIdentity();
2780 try {
2781 final Phone phone = getPhone(subId);
2782 if (phone != null) {
2783 return phone.getVoiceMessageCount();
2784 } else {
2785 return 0;
2786 }
2787 } finally {
2788 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002789 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002790 }
2791
2792 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002793 * returns true, if the device is in a state where both voice and data
2794 * are supported simultaneously. This can change based on location or network condition.
2795 */
2796 @Override
2797 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002798 final long identity = Binder.clearCallingIdentity();
2799 try {
2800 final Phone phone = getPhone(subId);
2801 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2802 } finally {
2803 Binder.restoreCallingIdentity(identity);
2804 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002805 }
2806
2807 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002808 * Send the dialer code if called from the current default dialer or the caller has
2809 * carrier privilege.
2810 * @param inputCode The dialer code to send
2811 */
2812 @Override
2813 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002814 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002815 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002816 String defaultDialer = TelecomManager.from(defaultPhone.getContext())
2817 .getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002818 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002819 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2820 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002821 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002822
2823 final long identity = Binder.clearCallingIdentity();
2824 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002825 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002826 } finally {
2827 Binder.restoreCallingIdentity(identity);
2828 }
fionaxu235cc5e2017-03-06 22:25:57 -08002829 }
2830
Pengquan Menga1bb6272018-09-06 09:59:22 -07002831 @Override
2832 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002833 if (!isActiveSubscription(subId)) {
2834 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2835 }
2836
Pengquan Menga1bb6272018-09-06 09:59:22 -07002837 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2838 }
2839
Brad Ebinger35c841c2018-10-01 10:40:55 -07002840 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002841 public boolean isInEmergencySmsMode() {
2842 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2843 final long identity = Binder.clearCallingIdentity();
2844 try {
2845 for (Phone phone : PhoneFactory.getPhones()) {
2846 if (phone.isInEmergencySmsMode()) {
2847 return true;
2848 }
2849 }
2850 } finally {
2851 Binder.restoreCallingIdentity(identity);
2852 }
2853 return false;
2854 }
2855
2856 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002857 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2858 throws RemoteException {
2859 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002860 final long token = Binder.clearCallingIdentity();
2861 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002862 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002863 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002864 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002865 } catch (ImsException e) {
2866 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002867 } finally {
2868 Binder.restoreCallingIdentity(token);
2869 }
2870 }
2871
2872 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002873 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2874 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002875 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2876 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2877 }
2878 Binder.withCleanCallingIdentity(() -> {
2879 try {
2880 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002881 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002882 .removeRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002883 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002884 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2885 + "is inactive, ignoring unregister.");
2886 // If the subscription is no longer active, just return, since the callback
2887 // will already have been removed internally.
2888 }
2889 });
Brad Ebinger35c841c2018-10-01 10:40:55 -07002890 }
2891
2892 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002893 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2894 throws RemoteException {
2895 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002896 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2897 final long token = Binder.clearCallingIdentity();
2898 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002899 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002900 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002901 } catch (ImsException e) {
2902 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002903 } finally {
2904 Binder.restoreCallingIdentity(token);
2905 }
2906 }
2907
2908 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002909 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2910 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002911
2912 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2913 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2914 }
2915 Binder.withCleanCallingIdentity(() -> {
2916 try {
2917 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002918 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002919 .removeCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002920 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002921 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
2922 + "is inactive, ignoring unregister.");
2923 // If the subscription is no longer active, just return, since the callback
2924 // will already have been removed internally.
2925 }
2926 });
Brad Ebinger35c841c2018-10-01 10:40:55 -07002927 }
2928
2929 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002930 public boolean isCapable(int subId, int capability, int regTech) {
2931 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002932 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2933 final long token = Binder.clearCallingIdentity();
2934 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002935 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002936 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002937 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002938 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2939 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002940 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08002941 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
2942 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07002943 } finally {
2944 Binder.restoreCallingIdentity(token);
2945 }
2946 }
2947
2948 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002949 public boolean isAvailable(int subId, int capability, int regTech) {
2950 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002951 final long token = Binder.clearCallingIdentity();
2952 try {
2953 Phone phone = getPhone(subId);
2954 if (phone == null) return false;
2955 return phone.isImsCapabilityAvailable(capability, regTech);
2956 } finally {
2957 Binder.restoreCallingIdentity(token);
2958 }
2959 }
2960
2961 @Override
2962 public boolean isAdvancedCallingSettingEnabled(int subId) {
2963 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2964 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2965 final long token = Binder.clearCallingIdentity();
2966 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002967 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002968 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002969 } catch (ImsException e) {
2970 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002971 } finally {
2972 Binder.restoreCallingIdentity(token);
2973 }
2974 }
2975
2976 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08002977 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002978 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08002979 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002980 final long identity = Binder.clearCallingIdentity();
2981 try {
2982 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002983 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002984 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002985 } catch (ImsException e) {
2986 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002987 } finally {
2988 Binder.restoreCallingIdentity(identity);
2989 }
2990 }
2991
2992 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002993 public boolean isVtSettingEnabled(int subId) {
2994 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002995 final long identity = Binder.clearCallingIdentity();
2996 try {
2997 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002998 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
2999 } catch (ImsException e) {
3000 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003001 } finally {
3002 Binder.restoreCallingIdentity(identity);
3003 }
3004 }
3005
3006 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003007 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003008 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003009 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003010 final long identity = Binder.clearCallingIdentity();
3011 try {
3012 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003013 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003014 } catch (ImsException e) {
3015 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003016 } finally {
3017 Binder.restoreCallingIdentity(identity);
3018 }
3019 }
3020
3021 @Override
3022 public boolean isVoWiFiSettingEnabled(int subId) {
3023 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3024 final long identity = Binder.clearCallingIdentity();
3025 try {
3026 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003027 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003028 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003029 } catch (ImsException e) {
3030 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003031 } finally {
3032 Binder.restoreCallingIdentity(identity);
3033 }
3034 }
3035
3036 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003037 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003038 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003039 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003040 final long identity = Binder.clearCallingIdentity();
3041 try {
3042 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003043 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003044 } catch (ImsException e) {
3045 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003046 } finally {
3047 Binder.restoreCallingIdentity(identity);
3048 }
3049 }
3050
3051 @Override
3052 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3053 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3054 final long identity = Binder.clearCallingIdentity();
3055 try {
3056 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003057 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003058 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003059 } catch (ImsException e) {
3060 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003061 } finally {
3062 Binder.restoreCallingIdentity(identity);
3063 }
3064 }
3065
3066 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003067 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003068 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003069 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003070 final long identity = Binder.clearCallingIdentity();
3071 try {
3072 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003073 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003074 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003075 } catch (ImsException e) {
3076 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003077 } finally {
3078 Binder.restoreCallingIdentity(identity);
3079 }
3080 }
3081
3082 @Override
3083 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3084 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3085 "setVoWiFiNonPersistent");
3086 final long identity = Binder.clearCallingIdentity();
3087 try {
3088 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003089 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003090 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003091 } catch (ImsException e) {
3092 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003093 } finally {
3094 Binder.restoreCallingIdentity(identity);
3095 }
3096 }
3097
3098 @Override
3099 public int getVoWiFiModeSetting(int subId) {
3100 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3101 final long identity = Binder.clearCallingIdentity();
3102 try {
3103 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003104 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003105 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003106 } catch (ImsException e) {
3107 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003108 } finally {
3109 Binder.restoreCallingIdentity(identity);
3110 }
3111 }
3112
3113 @Override
3114 public void setVoWiFiModeSetting(int subId, int mode) {
3115 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3116 "setVoWiFiModeSetting");
3117 final long identity = Binder.clearCallingIdentity();
3118 try {
3119 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003120 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003121 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003122 } catch (ImsException e) {
3123 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003124 } finally {
3125 Binder.restoreCallingIdentity(identity);
3126 }
3127 }
3128
3129 @Override
3130 public int getVoWiFiRoamingModeSetting(int subId) {
3131 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3132 final long identity = Binder.clearCallingIdentity();
3133 try {
3134 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003135 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003136 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003137 } catch (ImsException e) {
3138 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003139 } finally {
3140 Binder.restoreCallingIdentity(identity);
3141 }
3142 }
3143
3144 @Override
3145 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3146 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3147 "setVoWiFiRoamingModeSetting");
3148 final long identity = Binder.clearCallingIdentity();
3149 try {
3150 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003151 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003152 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003153 } catch (ImsException e) {
3154 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003155 } finally {
3156 Binder.restoreCallingIdentity(identity);
3157 }
3158 }
3159
3160 @Override
3161 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3162 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3163 "setRttCapabilityEnabled");
3164 final long identity = Binder.clearCallingIdentity();
3165 try {
3166 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003167 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3168 } catch (ImsException e) {
3169 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003170 } finally {
3171 Binder.restoreCallingIdentity(identity);
3172 }
3173 }
3174
3175 @Override
3176 public boolean isTtyOverVolteEnabled(int subId) {
3177 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3178 final long identity = Binder.clearCallingIdentity();
3179 try {
3180 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003181 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003182 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003183 } catch (ImsException e) {
3184 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003185 } finally {
3186 Binder.restoreCallingIdentity(identity);
3187 }
3188 }
3189
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003190 @Override
3191 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3192 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3193 final long identity = Binder.clearCallingIdentity();
3194 try {
3195 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003196 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003197 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003198 } catch (ImsException e) {
3199 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003200 } finally {
3201 Binder.restoreCallingIdentity(identity);
3202 }
3203 }
3204
3205 @Override
3206 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3207 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3208 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003209 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3210 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3211 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003212 try {
3213 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003214 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003215 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003216 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003217 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3218 + "is inactive, ignoring unregister.");
3219 // If the subscription is no longer active, just return, since the callback will already
3220 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003221 } finally {
3222 Binder.restoreCallingIdentity(identity);
3223 }
3224 }
3225
3226 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003227 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3228 boolean isProvisioned) {
3229 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3230 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3231 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3232 }
3233 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3234 "setProvisioningStatusForCapability");
3235 final long identity = Binder.clearCallingIdentity();
3236 try {
3237 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3238 Phone phone = getPhone(subId);
3239 if (phone == null) {
3240 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3241 + subId);
3242 return;
3243 }
3244 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3245 return;
3246 }
3247
3248 // this capability requires provisioning, route to the correct API.
3249 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3250 switch (capability) {
3251 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3252 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3253 ims.setVolteProvisioned(isProvisioned);
3254 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3255 ims.setWfcProvisioned(isProvisioned);
3256 }
3257 break;
3258 }
3259 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3260 // There is currently no difference in VT provisioning type.
3261 ims.setVtProvisioned(isProvisioned);
3262 break;
3263 }
3264 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3265 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3266 // change the capability of the feature instead if needed.
3267 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3268 == isProvisioned) {
3269 // No change in provisioning.
3270 return;
3271 }
3272 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3273 try {
3274 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003275 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003276 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3277 + ", Exception" + e.getMessage());
3278 }
3279 break;
3280 }
3281 default: {
3282 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3283 + capability + "', which does not require provisioning.");
3284 }
3285 }
3286
3287 } finally {
3288 Binder.restoreCallingIdentity(identity);
3289 }
3290 }
3291
3292 @Override
3293 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3294 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3295 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3296 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3297 }
3298 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3299 final long identity = Binder.clearCallingIdentity();
3300 try {
3301 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3302 Phone phone = getPhone(subId);
3303 if (phone == null) {
3304 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3305 + subId);
3306 // We will fail with "true" as the provisioning status because this is the default
3307 // if we do not require provisioning.
3308 return true;
3309 }
3310
3311 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3312 return true;
3313 }
3314
3315 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3316 switch (capability) {
3317 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3318 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3319 return ims.isVolteProvisionedOnDevice();
3320 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3321 return ims.isWfcProvisionedOnDevice();
3322 }
3323 // This should never happen, since we are checking tech above to make sure it
3324 // is either LTE or IWLAN.
3325 throw new IllegalArgumentException("Invalid radio technology for voice "
3326 + "capability.");
3327 }
3328 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3329 // There is currently no difference in VT provisioning type.
3330 return ims.isVtProvisionedOnDevice();
3331 }
3332 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3333 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3334 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3335 }
3336 default: {
3337 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3338 + capability + "', which does not require provisioning.");
3339 }
3340 }
3341
3342 } finally {
3343 Binder.restoreCallingIdentity(identity);
3344 }
3345 }
3346
3347 @Override
3348 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3349 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3350 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3351 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3352 }
3353 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3354 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3355 return (provisionedBits & capability) > 0;
3356 }
3357
3358 @Override
3359 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3360 boolean isProvisioned) {
3361 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3362 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3363 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3364 }
3365 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3366 "setProvisioningStatusForCapability");
3367 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3368 // If the current provisioning status for capability already matches isProvisioned,
3369 // do nothing.
3370 if (((provisionedBits & capability) > 0) == isProvisioned) {
3371 return;
3372 }
3373 if (isProvisioned) {
3374 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3375 } else {
3376 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3377 }
3378 }
3379
3380 /**
3381 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3382 * technology. The bitfield should mirror the bitfield defined by
3383 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3384 */
3385 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3386 String key = getMmTelProvisioningKey(subId, tech);
3387 // Default is no capabilities are provisioned.
3388 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3389 }
3390
3391 /**
3392 * Sets the MmTel capability provisioning bitfield (defined by
3393 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3394 * technology specified.
3395 *
3396 * Note: This is a synchronous command and should not be called on UI thread.
3397 */
3398 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3399 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3400 String key = getMmTelProvisioningKey(subId, tech);
3401 editor.putInt(key, newField);
3402 editor.commit();
3403 }
3404
3405 private static String getMmTelProvisioningKey(int subId, int tech) {
3406 // resulting key is provision_ims_mmtel_{subId}_{tech}
3407 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3408 }
3409
3410 /**
3411 * Query CarrierConfig to see if the specified capability requires provisioning for the
3412 * carrier associated with the subscription id.
3413 */
3414 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3415 int capability) {
3416 CarrierConfigManager configManager = new CarrierConfigManager(context);
3417 PersistableBundle c = configManager.getConfigForSubId(subId);
3418 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07003419 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003420 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3421 false);
3422 boolean requireVoiceVtProvisioning = c.getBoolean(
3423 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3424
3425 // First check to make sure that the capability requires provisioning.
3426 switch (capability) {
3427 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3428 // intentional fallthrough
3429 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3430 if (requireVoiceVtProvisioning) {
3431 // Voice and Video requires provisioning
3432 return true;
3433 }
3434 break;
3435 }
3436 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3437 if (requireUtProvisioning) {
3438 // UT requires provisioning
3439 return true;
3440 }
3441 break;
3442 }
3443 }
3444 return false;
3445 }
3446
3447 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003448 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003449 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3450 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3451 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003452 enforceReadPrivilegedPermission("getImsProvisioningInt");
3453 final long identity = Binder.clearCallingIdentity();
3454 try {
3455 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003456 int slotId = getSlotIndex(subId);
3457 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3458 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3459 + subId + "' for key:" + key);
3460 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3461 }
3462 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003463 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003464 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3465 + subId + "' for key:" + key);
3466 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003467 } finally {
3468 Binder.restoreCallingIdentity(identity);
3469 }
3470 }
3471
3472 @Override
3473 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003474 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3475 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3476 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003477 enforceReadPrivilegedPermission("getImsProvisioningString");
3478 final long identity = Binder.clearCallingIdentity();
3479 try {
3480 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003481 int slotId = getSlotIndex(subId);
3482 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3483 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3484 + subId + "' for key:" + key);
3485 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3486 }
3487 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003488 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003489 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3490 + subId + "' for key:" + key);
3491 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003492 } finally {
3493 Binder.restoreCallingIdentity(identity);
3494 }
3495 }
3496
3497 @Override
3498 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003499 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3500 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3501 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003502 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3503 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003504 final long identity = Binder.clearCallingIdentity();
3505 try {
3506 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003507 int slotId = getSlotIndex(subId);
3508 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3509 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3510 + subId + "' for key:" + key);
3511 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3512 }
3513 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003514 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003515 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3516 + "' for key:" + key);
3517 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003518 } finally {
3519 Binder.restoreCallingIdentity(identity);
3520 }
3521 }
3522
3523 @Override
3524 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003525 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3526 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3527 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003528 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3529 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003530 final long identity = Binder.clearCallingIdentity();
3531 try {
3532 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003533 int slotId = getSlotIndex(subId);
3534 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3535 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3536 + subId + "' for key:" + key);
3537 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3538 }
3539 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003540 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003541 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3542 + "' for key:" + key);
3543 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003544 } finally {
3545 Binder.restoreCallingIdentity(identity);
3546 }
3547 }
3548
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003549 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003550 int slotId = SubscriptionManager.getSlotIndex(subId);
3551 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003552 throw new ImsException("Invalid Subscription Id, subId=" + subId,
3553 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003554 }
3555 return slotId;
3556 }
3557
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003558 private int getSlotIndex(int subId) {
3559 int slotId = SubscriptionManager.getSlotIndex(subId);
3560 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3561 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3562 }
3563 return slotId;
3564 }
3565
Wink Saville36469e72014-06-11 15:17:00 -07003566 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07003567 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07003568 */
3569 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003570 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07003571 final int targetSdk = getTargetSdk(callingPackage);
3572 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
3573 return getDataNetworkTypeForSubscriber(subId, callingPackage);
3574 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07003575 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
3576 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003577 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3578 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003579
Malcolm Chenaa4a8532018-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().getDataNetworkType();
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 * Returns the data network type
3595 */
3596 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003597 public int getDataNetworkType(String callingPackage) {
3598 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003599 }
3600
3601 /**
3602 * Returns the data network type for a subId
3603 */
3604 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003605 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003606 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003607 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003608 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3609 }
3610
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003611 final long identity = Binder.clearCallingIdentity();
3612 try {
3613 final Phone phone = getPhone(subId);
3614 if (phone != null) {
3615 return phone.getServiceState().getDataNetworkType();
3616 } else {
3617 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3618 }
3619 } finally {
3620 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003621 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003622 }
3623
3624 /**
Wink Saville36469e72014-06-11 15:17:00 -07003625 * Returns the Voice network type for a subId
3626 */
3627 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003628 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003629 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003630 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003631 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3632 }
3633
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003634 final long identity = Binder.clearCallingIdentity();
3635 try {
3636 final Phone phone = getPhone(subId);
3637 if (phone != null) {
3638 return phone.getServiceState().getVoiceNetworkType();
3639 } else {
3640 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3641 }
3642 } finally {
3643 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003644 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003645 }
3646
3647 /**
3648 * @return true if a ICC card is present
3649 */
3650 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003651 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003652 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3653 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003654 }
3655
3656 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003657 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003658 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003659 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003660 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003661 final long identity = Binder.clearCallingIdentity();
3662 try {
3663 final Phone phone = PhoneFactory.getPhone(slotIndex);
3664 if (phone != null) {
3665 return phone.getIccCard().hasIccCard();
3666 } else {
3667 return false;
3668 }
3669 } finally {
3670 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003671 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003672 }
3673
3674 /**
3675 * Return if the current radio is LTE on CDMA. This
3676 * is a tri-state return value as for a period of time
3677 * the mode may be unknown.
3678 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003679 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003680 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003681 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003682 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003683 @Override
3684 public int getLteOnCdmaMode(String callingPackage) {
3685 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003686 }
3687
Sanket Padawe356d7632015-06-22 14:03:32 -07003688 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003689 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003690 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003691 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003692 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3693 }
3694
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003695 final long identity = Binder.clearCallingIdentity();
3696 try {
3697 final Phone phone = getPhone(subId);
3698 if (phone == null) {
3699 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3700 } else {
3701 return phone.getLteOnCdmaMode();
3702 }
3703 } finally {
3704 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003705 }
Wink Saville36469e72014-06-11 15:17:00 -07003706 }
3707
Wink Saville36469e72014-06-11 15:17:00 -07003708 /**
3709 * {@hide}
3710 * Returns Default subId, 0 in the case of single standby.
3711 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003712 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003713 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003714 }
3715
Shishir Agrawala9f32182016-04-12 12:00:16 -07003716 private int getSlotForDefaultSubscription() {
3717 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3718 }
3719
Wink Savilleb564aae2014-10-23 10:18:09 -07003720 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003721 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003722 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003723
Pengquan Menge92a50d2018-09-21 15:54:48 -07003724 private boolean isActiveSubscription(int subId) {
3725 return mSubscriptionController.isActiveSubId(subId);
3726 }
3727
Ihab Awadf2177b72013-11-25 13:33:23 -08003728 /**
3729 * @see android.telephony.TelephonyManager.WifiCallingChoices
3730 */
3731 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003732 final long identity = Binder.clearCallingIdentity();
3733 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003734 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003735 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3736 getWhenToMakeWifiCallsDefaultPreference());
3737 } finally {
3738 Binder.restoreCallingIdentity(identity);
3739 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003740 }
3741
3742 /**
3743 * @see android.telephony.TelephonyManager.WifiCallingChoices
3744 */
3745 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003746 final long identity = Binder.clearCallingIdentity();
3747 try {
3748 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003749 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003750 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3751 } finally {
3752 Binder.restoreCallingIdentity(identity);
3753 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003754 }
3755
Sailesh Nepald1e68152013-12-12 19:08:02 -08003756 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003757 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003758 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003759 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003760
Jordan Liu4c733742019-02-28 12:03:40 -08003761 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
3762 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
3763 if (phoneId == -1) {
3764 throw new IllegalArgumentException("Given slot index: " + slotIndex
3765 + " does not correspond to an active phone");
3766 }
3767 return PhoneFactory.getPhone(phoneId);
3768 }
3769
Shishir Agrawal566b7612013-10-28 14:41:00 -07003770 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003771 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3772 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003773 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3774 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003775 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08003776 if (DBG) {
3777 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3778 }
3779 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
3780 p2);
3781 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003782
Jordan Liu4c733742019-02-28 12:03:40 -08003783
3784 @Override
3785 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
3786 int slotIndex, String callingPackage, String aid, int p2) {
3787 enforceModifyPermission();
3788 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3789 if (DBG) {
3790 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
3791 }
3792 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3793 callingPackage, aid, p2);
3794 }
3795
3796 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
3797 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003798 final long identity = Binder.clearCallingIdentity();
3799 try {
3800 if (TextUtils.equals(ISDR_AID, aid)) {
3801 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003802 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3803 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003804 if (bestComponent == null
3805 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3806 loge("The calling package is not allowed to access ISD-R.");
3807 throw new SecurityException(
3808 "The calling package is not allowed to access ISD-R.");
3809 }
Derek Tan740e1672017-06-27 14:56:27 -07003810 }
Derek Tan740e1672017-06-27 14:56:27 -07003811
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003812 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08003813 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
3814 null /* workSource */);
3815 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003816 return response;
3817 } finally {
3818 Binder.restoreCallingIdentity(identity);
3819 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003820 }
3821
3822 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003823 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003824 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3825 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08003826 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3827 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
3828 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003829
Jordan Liu4c733742019-02-28 12:03:40 -08003830 @Override
3831 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
3832 enforceModifyPermission();
3833 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
3834 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3835 channel);
3836 }
3837
3838 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003839 final long identity = Binder.clearCallingIdentity();
3840 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003841 if (channel < 0) {
3842 return false;
3843 }
Jordan Liu4c733742019-02-28 12:03:40 -08003844 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
3845 null /* workSource */);
3846 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003847 return success;
3848 } finally {
3849 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003850 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003851 }
3852
3853 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003854 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003855 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003856 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3857 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08003858 if (DBG) {
3859 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3860 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3861 + p3 + " data=" + data);
3862 }
3863 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
3864 command, p1, p2, p3, data);
3865 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003866
Jordan Liu4c733742019-02-28 12:03:40 -08003867 @Override
3868 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
3869 int command, int p1, int p2, int p3, String data) {
3870 enforceModifyPermission();
3871 if (DBG) {
3872 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
3873 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3874 + p3 + " data=" + data);
3875 }
3876 return iccTransmitApduLogicalChannelWithPermission(
3877 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
3878 data);
3879 }
3880
3881 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
3882 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003883 final long identity = Binder.clearCallingIdentity();
3884 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07003885 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003886 return "";
3887 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003888
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003889 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08003890 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
3891 null /* workSource */);
3892 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003893
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003894 // Append the returned status code to the end of the response payload.
3895 String s = Integer.toHexString(
3896 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3897 if (response.payload != null) {
3898 s = IccUtils.bytesToHexString(response.payload) + s;
3899 }
3900 return s;
3901 } finally {
3902 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003903 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003904 }
Jake Hambye994d462014-02-03 13:10:13 -08003905
Evan Charltonc66da362014-05-16 14:06:40 -07003906 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003907 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3908 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003909 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3910 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003911 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08003912 if (DBG) {
3913 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3914 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3915 }
3916 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
3917 cla, command, p1, p2, p3, data);
3918 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003919
Jordan Liu4c733742019-02-28 12:03:40 -08003920 @Override
3921 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
3922 int command, int p1, int p2, int p3, String data) {
3923 enforceModifyPermission();
3924 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3925 if (DBG) {
3926 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
3927 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
3928 + " data=" + data);
3929 }
3930
3931 return iccTransmitApduBasicChannelWithPermission(
3932 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
3933 p2, p3, data);
3934 }
3935
3936 // open APDU basic channel assuming the caller has sufficient permissions
3937 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
3938 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003939 final long identity = Binder.clearCallingIdentity();
3940 try {
3941 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3942 && TextUtils.equals(ISDR_AID, data)) {
3943 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003944 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3945 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003946 if (bestComponent == null
3947 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3948 loge("The calling package is not allowed to select ISD-R.");
3949 throw new SecurityException(
3950 "The calling package is not allowed to select ISD-R.");
3951 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003952 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003953
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003954 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08003955 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
3956 null /* workSource */);
3957 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003958
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003959 // Append the returned status code to the end of the response payload.
3960 String s = Integer.toHexString(
3961 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3962 if (response.payload != null) {
3963 s = IccUtils.bytesToHexString(response.payload) + s;
3964 }
3965 return s;
3966 } finally {
3967 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003968 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003969 }
3970
3971 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003972 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003973 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003974 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3975 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003976
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003977 final long identity = Binder.clearCallingIdentity();
3978 try {
3979 if (DBG) {
3980 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3981 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3982 }
3983
3984 IccIoResult response =
3985 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3986 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3987 subId);
3988
3989 if (DBG) {
3990 log("Exchange SIM_IO [R]" + response);
3991 }
3992
3993 byte[] result = null;
3994 int length = 2;
3995 if (response.payload != null) {
3996 length = 2 + response.payload.length;
3997 result = new byte[length];
3998 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3999 } else {
4000 result = new byte[length];
4001 }
4002
4003 result[length - 1] = (byte) response.sw2;
4004 result[length - 2] = (byte) response.sw1;
4005 return result;
4006 } finally {
4007 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004008 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004009 }
4010
Nathan Haroldb3014052017-01-25 15:57:32 -08004011 /**
4012 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4013 * on a particular subscription
4014 */
sqianb6e41952018-03-12 14:54:01 -07004015 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
4016 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4017 mApp, subId, callingPackage, "getForbiddenPlmns")) {
4018 return null;
4019 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004020
4021 final long identity = Binder.clearCallingIdentity();
4022 try {
4023 if (appType != TelephonyManager.APPTYPE_USIM
4024 && appType != TelephonyManager.APPTYPE_SIM) {
4025 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4026 return null;
4027 }
4028 Object response = sendRequest(
4029 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4030 if (response instanceof String[]) {
4031 return (String[]) response;
4032 }
4033 // Response is an Exception of some kind,
4034 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004035 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004036 } finally {
4037 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004038 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004039 }
4040
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004041 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004042 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004043 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4044 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004045
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004046 final long identity = Binder.clearCallingIdentity();
4047 try {
4048 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4049 if (response.payload == null) {
4050 return "";
4051 }
Evan Charltonc66da362014-05-16 14:06:40 -07004052
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004053 // Append the returned status code to the end of the response payload.
4054 String s = Integer.toHexString(
4055 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4056 s = IccUtils.bytesToHexString(response.payload) + s;
4057 return s;
4058 } finally {
4059 Binder.restoreCallingIdentity(identity);
4060 }
Evan Charltonc66da362014-05-16 14:06:40 -07004061 }
4062
Jake Hambye994d462014-02-03 13:10:13 -08004063 /**
4064 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4065 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4066 *
4067 * @param itemID the ID of the item to read
4068 * @return the NV item as a String, or null on error.
4069 */
4070 @Override
4071 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004072 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004073 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4074 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004075
4076 final long identity = Binder.clearCallingIdentity();
4077 try {
4078 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004079 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004080 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4081 return value;
4082 } finally {
4083 Binder.restoreCallingIdentity(identity);
4084 }
Jake Hambye994d462014-02-03 13:10:13 -08004085 }
4086
4087 /**
4088 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4089 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4090 *
4091 * @param itemID the ID of the item to read
4092 * @param itemValue the value to write, as a String
4093 * @return true on success; false on any failure
4094 */
4095 @Override
4096 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004097 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004098 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4099 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004100
4101 final long identity = Binder.clearCallingIdentity();
4102 try {
4103 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4104 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004105 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004106 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4107 return success;
4108 } finally {
4109 Binder.restoreCallingIdentity(identity);
4110 }
Jake Hambye994d462014-02-03 13:10:13 -08004111 }
4112
4113 /**
4114 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4115 * Used for device configuration by some CDMA operators.
4116 *
4117 * @param preferredRoamingList byte array containing the new PRL
4118 * @return true on success; false on any failure
4119 */
4120 @Override
4121 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004122 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4123 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004124
4125 final long identity = Binder.clearCallingIdentity();
4126 try {
4127 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4128 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4129 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4130 return success;
4131 } finally {
4132 Binder.restoreCallingIdentity(identity);
4133 }
Jake Hambye994d462014-02-03 13:10:13 -08004134 }
4135
4136 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004137 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004138 * Used for device configuration by some CDMA operators.
4139 *
chen xu6dac5ab2018-10-26 17:39:23 -07004140 * @param slotIndex - device slot.
4141 *
Jake Hambye994d462014-02-03 13:10:13 -08004142 * @return true on success; false on any failure
4143 */
4144 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004145 public boolean resetModemConfig(int slotIndex) {
4146 Phone phone = PhoneFactory.getPhone(slotIndex);
4147 if (phone != null) {
4148 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4149 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004150
chen xu6dac5ab2018-10-26 17:39:23 -07004151 final long identity = Binder.clearCallingIdentity();
4152 try {
4153 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4154 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4155 return success;
4156 } finally {
4157 Binder.restoreCallingIdentity(identity);
4158 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004159 }
chen xu6dac5ab2018-10-26 17:39:23 -07004160 return false;
4161 }
4162
4163 /**
4164 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4165 *
4166 * @param slotIndex - device slot.
4167 *
4168 * @return true on success; false on any failure
4169 */
4170 @Override
4171 public boolean rebootModem(int slotIndex) {
4172 Phone phone = PhoneFactory.getPhone(slotIndex);
4173 if (phone != null) {
4174 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4175 mApp, phone.getSubId(), "rebootModem");
4176
4177 final long identity = Binder.clearCallingIdentity();
4178 try {
4179 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4180 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4181 return success;
4182 } finally {
4183 Binder.restoreCallingIdentity(identity);
4184 }
4185 }
4186 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004187 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004188
Svet Ganovb320e182015-04-16 12:30:10 -07004189 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004190 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004191 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004192 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004193 return new String[0];
4194 }
4195
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004196 final long identity = Binder.clearCallingIdentity();
4197 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004198 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004199 } finally {
4200 Binder.restoreCallingIdentity(identity);
4201 }
Wink Saville36469e72014-06-11 15:17:00 -07004202 }
4203
Brad Ebinger51f743a2017-01-23 13:50:20 -08004204 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004205 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4206 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004207 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004208 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004209 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004210
4211 final long identity = Binder.clearCallingIdentity();
4212 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004213 ImsResolver resolver = PhoneFactory.getImsResolver();
4214 if (resolver == null) {
4215 // may happen if the device does not support IMS.
4216 return;
4217 }
4218 resolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004219 } finally {
4220 Binder.restoreCallingIdentity(identity);
4221 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004222 }
4223
4224 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004225 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4226 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004227 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004228 public void disableIms(int slotId) {
4229 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004230
4231 final long identity = Binder.clearCallingIdentity();
4232 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004233 ImsResolver resolver = PhoneFactory.getImsResolver();
4234 if (resolver == null) {
4235 // may happen if the device does not support IMS.
4236 return;
4237 }
4238 resolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004239 } finally {
4240 Binder.restoreCallingIdentity(identity);
4241 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004242 }
4243
4244 /**
4245 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4246 * feature or {@link null} if the service is not available. If the feature is available, the
4247 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4248 */
4249 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004250 IImsServiceFeatureCallback callback) {
4251 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004252
4253 final long identity = Binder.clearCallingIdentity();
4254 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004255 ImsResolver resolver = PhoneFactory.getImsResolver();
4256 if (resolver == null) {
4257 // may happen if the device does not support IMS.
4258 return null;
4259 }
4260 return resolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004261 } finally {
4262 Binder.restoreCallingIdentity(identity);
4263 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004264 }
4265
4266 /**
4267 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4268 * feature during emergency calling or {@link null} if the service is not available. If the
4269 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4270 * listener for feature updates.
4271 */
4272 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4273 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004274
4275 final long identity = Binder.clearCallingIdentity();
4276 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004277 ImsResolver resolver = PhoneFactory.getImsResolver();
4278 if (resolver == null) {
4279 // may happen if the device does not support IMS.
4280 return null;
4281 }
4282 return resolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004283 } finally {
4284 Binder.restoreCallingIdentity(identity);
4285 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004286 }
4287
Brad Ebinger5f64b052017-12-14 14:26:15 -08004288 /**
4289 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004290 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004291 */
4292 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4293 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004294
4295 final long identity = Binder.clearCallingIdentity();
4296 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004297 ImsResolver resolver = PhoneFactory.getImsResolver();
4298 if (resolver == null) {
4299 // may happen if the device does not support IMS.
4300 return null;
4301 }
4302 return resolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004303 } finally {
4304 Binder.restoreCallingIdentity(identity);
4305 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004306 }
4307
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004308 /**
4309 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004310 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004311 */
4312 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4313 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004314
4315 final long identity = Binder.clearCallingIdentity();
4316 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004317 ImsResolver resolver = PhoneFactory.getImsResolver();
4318 if (resolver == null) {
4319 // may happen if the device does not support IMS.
4320 return null;
4321 }
4322 return resolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004323 } finally {
4324 Binder.restoreCallingIdentity(identity);
4325 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004326 }
4327
Brad Ebinger884c07b2018-02-15 16:17:40 -08004328 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004329 * Sets the ImsService Package Name that Telephony will bind to.
4330 *
4331 * @param slotId the slot ID that the ImsService should bind for.
4332 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4333 * ImsService is the device default ImsService.
4334 * @param packageName The package name of the application that contains the ImsService to bind
4335 * to.
4336 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4337 * @hide
4338 */
4339 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004340 int[] subIds = SubscriptionManager.getSubId(slotId);
4341 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4342 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4343 "setImsService");
4344
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004345 final long identity = Binder.clearCallingIdentity();
4346 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004347 ImsResolver resolver = PhoneFactory.getImsResolver();
4348 if (resolver == null) {
4349 // may happen if the device does not support IMS.
4350 return false;
4351 }
4352 return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService,
4353 packageName);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004354 } finally {
4355 Binder.restoreCallingIdentity(identity);
4356 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004357 }
4358
4359 /**
4360 * Return the ImsService configuration.
4361 *
4362 * @param slotId The slot that the ImsService is associated with.
4363 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4364 * the device default.
4365 * @return the package name of the ImsService configuration.
4366 */
4367 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004368 int[] subIds = SubscriptionManager.getSubId(slotId);
4369 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4370 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4371 "getImsService");
4372
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004373 final long identity = Binder.clearCallingIdentity();
4374 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004375 ImsResolver resolver = PhoneFactory.getImsResolver();
4376 if (resolver == null) {
4377 // may happen if the device does not support IMS.
4378 return "";
4379 }
4380 return resolver.getImsServiceConfiguration(slotId, isCarrierImsService);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004381 } finally {
4382 Binder.restoreCallingIdentity(identity);
4383 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004384 }
4385
Wink Saville36469e72014-06-11 15:17:00 -07004386 public void setImsRegistrationState(boolean registered) {
4387 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004388
4389 final long identity = Binder.clearCallingIdentity();
4390 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004391 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004392 } finally {
4393 Binder.restoreCallingIdentity(identity);
4394 }
Wink Saville36469e72014-06-11 15:17:00 -07004395 }
4396
4397 /**
Stuart Scott54788802015-03-30 13:18:01 -07004398 * Set the network selection mode to automatic.
4399 *
4400 */
4401 @Override
4402 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004403 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4404 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004405
Pengquan Menge92a50d2018-09-21 15:54:48 -07004406 if (!isActiveSubscription(subId)) {
4407 return;
4408 }
4409
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004410 final long identity = Binder.clearCallingIdentity();
4411 try {
4412 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4413 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4414 } finally {
4415 Binder.restoreCallingIdentity(identity);
4416 }
Stuart Scott54788802015-03-30 13:18:01 -07004417 }
4418
Pengquan Mengea84e042018-09-20 14:57:26 -07004419 /**
4420 * Ask the radio to connect to the input network and change selection mode to manual.
4421 *
4422 * @param subId the id of the subscription.
4423 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4424 * the operator to attach to.
4425 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4426 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4427 * normal network selection next time.
4428 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004429 */
4430 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004431 public boolean setNetworkSelectionModeManual(
4432 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004433 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4434 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004435
4436 if (!isActiveSubscription(subId)) {
4437 return false;
4438 }
4439
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004440 final long identity = Binder.clearCallingIdentity();
4441 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004442 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004443 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004444 if (DBG) {
4445 log("setNetworkSelectionModeManual: subId: " + subId
4446 + " operator: " + operatorInfo);
4447 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004448 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4449 } finally {
4450 Binder.restoreCallingIdentity(identity);
4451 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004452 }
4453
4454 /**
4455 * Scans for available networks.
4456 */
4457 @Override
Hall Liuf19c44f2018-11-27 14:38:17 -08004458 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004459 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4460 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004461 LocationAccessPolicy.LocationPermissionResult locationResult =
4462 LocationAccessPolicy.checkLocationPermission(mApp,
4463 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4464 .setCallingPackage(callingPackage)
4465 .setCallingPid(Binder.getCallingPid())
4466 .setCallingUid(Binder.getCallingUid())
4467 .setMethod("getCellNetworkScanResults")
4468 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4469 .build());
4470 switch (locationResult) {
4471 case DENIED_HARD:
4472 throw new SecurityException("Not allowed to access scan results -- location");
4473 case DENIED_SOFT:
4474 return null;
4475 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004476
Pengquan Menga1bb6272018-09-06 09:59:22 -07004477 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004478 try {
4479 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004480 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004481 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004482 } finally {
4483 Binder.restoreCallingIdentity(identity);
4484 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004485 }
4486
4487 /**
yinxub1bed742017-04-17 11:45:04 -07004488 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004489 *
yinxub1bed742017-04-17 11:45:04 -07004490 * @param subId id of the subscription
4491 * @param request contains the radio access networks with bands/channels to scan
4492 * @param messenger callback messenger for scan results or errors
4493 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004494 * @return the id of the requested scan which can be used to stop the scan.
4495 */
4496 @Override
4497 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Hall Liuf19c44f2018-11-27 14:38:17 -08004498 IBinder binder, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004499 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4500 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004501 LocationAccessPolicy.LocationPermissionResult locationResult =
4502 LocationAccessPolicy.checkLocationPermission(mApp,
4503 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4504 .setCallingPackage(callingPackage)
4505 .setCallingPid(Binder.getCallingPid())
4506 .setCallingUid(Binder.getCallingUid())
4507 .setMethod("requestNetworkScan")
4508 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4509 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004510 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07004511 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08004512 if (e != null) {
4513 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4514 throw e;
4515 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07004516 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004517 return TelephonyScanManager.INVALID_SCAN_ID;
4518 }
4519 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004520 }
Hall Liu912dfd32019-04-25 14:02:26 -07004521 int callingUid = Binder.getCallingUid();
4522 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07004523 final long identity = Binder.clearCallingIdentity();
4524 try {
4525 return mNetworkScanRequestTracker.startNetworkScan(
4526 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07004527 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07004528 } finally {
4529 Binder.restoreCallingIdentity(identity);
4530 }
yinxu504e1392017-04-12 16:03:22 -07004531 }
4532
Hall Liub2ac8ef2019-02-28 15:56:23 -08004533 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07004534 NetworkScanRequest request, int subId) {
4535 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
4536 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
4537 boolean hasNetworkScanPermission =
4538 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4539 == PERMISSION_GRANTED;
4540
4541 if (!hasCarrierPriv && !hasNetworkScanPermission) {
4542 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
4543 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08004544 }
4545
4546 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4547 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004548 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4549 return new SecurityException("Specific channels must not be"
4550 + " scanned without location access.");
4551 }
4552 }
4553 }
4554
Hall Liub2ac8ef2019-02-28 15:56:23 -08004555 return null;
4556 }
4557
yinxu504e1392017-04-12 16:03:22 -07004558 /**
4559 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004560 *
4561 * @param subId id of the subscription
4562 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004563 */
4564 @Override
4565 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004566 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4567 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004568
Hall Liu912dfd32019-04-25 14:02:26 -07004569 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004570 final long identity = Binder.clearCallingIdentity();
4571 try {
Hall Liu912dfd32019-04-25 14:02:26 -07004572 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004573 } finally {
4574 Binder.restoreCallingIdentity(identity);
4575 }
yinxu504e1392017-04-12 16:03:22 -07004576 }
4577
4578 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004579 * Get the calculated preferred network type.
4580 * Used for debugging incorrect network type.
4581 *
4582 * @return the preferred network type, defined in RILConstants.java.
4583 */
4584 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004585 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004586 final Phone defaultPhone = getDefaultPhone();
4587 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4588 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004589 return RILConstants.PREFERRED_NETWORK_MODE;
4590 }
4591
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004592 final long identity = Binder.clearCallingIdentity();
4593 try {
4594 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004595 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004596 } finally {
4597 Binder.restoreCallingIdentity(identity);
4598 }
Junda Liu84d15a22014-07-02 11:21:04 -07004599 }
4600
4601 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004602 * Get the preferred network type.
4603 * Used for device configuration by some CDMA operators.
4604 *
4605 * @return the preferred network type, defined in RILConstants.java.
4606 */
4607 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004608 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08004609 TelephonyPermissions
4610 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4611 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004612
4613 final long identity = Binder.clearCallingIdentity();
4614 try {
4615 if (DBG) log("getPreferredNetworkType");
4616 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4617 int networkType = (result != null ? result[0] : -1);
4618 if (DBG) log("getPreferredNetworkType: " + networkType);
4619 return networkType;
4620 } finally {
4621 Binder.restoreCallingIdentity(identity);
4622 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004623 }
4624
4625 /**
4626 * Set the preferred network type.
4627 * Used for device configuration by some CDMA operators.
4628 *
4629 * @param networkType the preferred network type, defined in RILConstants.java.
4630 * @return true on success; false on any failure.
4631 */
4632 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004633 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004634 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4635 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004636
4637 final long identity = Binder.clearCallingIdentity();
4638 try {
4639 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4640 Boolean success = (Boolean) sendRequest(
4641 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4642 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4643 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004644 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004645 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4646 }
4647 return success;
4648 } finally {
4649 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004650 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004651 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004652
4653 /**
Miaoa84611c2019-03-15 09:21:10 +08004654 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004655 *
Miaoa84611c2019-03-15 09:21:10 +08004656 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004657 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004658 * @hide
4659 */
4660 @Override
Miaoa84611c2019-03-15 09:21:10 +08004661 public boolean getTetherApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004662 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004663 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08004664 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004665 try {
Miaoa84611c2019-03-15 09:21:10 +08004666 if (phone != null) {
4667 return phone.hasMatchedTetherApnSetting();
4668 } else {
4669 return false;
4670 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004671 } finally {
4672 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004673 }
Junda Liu475951f2014-11-07 16:45:03 -08004674 }
4675
4676 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004677 * Set mobile data enabled
4678 * Used by the user through settings etc to turn on/off mobile data
4679 *
4680 * @param enable {@code true} turn turn data on, else {@code false}
4681 */
4682 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004683 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004684 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4685 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004686
4687 final long identity = Binder.clearCallingIdentity();
4688 try {
4689 int phoneId = mSubscriptionController.getPhoneId(subId);
4690 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4691 Phone phone = PhoneFactory.getPhone(phoneId);
4692 if (phone != null) {
4693 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08004694 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004695 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004696 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004697 }
4698 } finally {
4699 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004700 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004701 }
4702
4703 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004704 * Get the user enabled state of Mobile Data.
4705 *
4706 * TODO: remove and use isUserDataEnabled.
4707 * This can't be removed now because some vendor codes
4708 * calls through ITelephony directly while they should
4709 * use TelephonyManager.
4710 *
4711 * @return true on enabled
4712 */
4713 @Override
4714 public boolean getDataEnabled(int subId) {
4715 return isUserDataEnabled(subId);
4716 }
4717
4718 /**
4719 * Get whether mobile data is enabled per user setting.
4720 *
4721 * There are other factors deciding whether mobile data is actually enabled, but they are
4722 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004723 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004724 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004725 *
4726 * @return {@code true} if data is enabled else {@code false}
4727 */
4728 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004729 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004730 try {
4731 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4732 null);
4733 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004734 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4735 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004736 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004737
4738 final long identity = Binder.clearCallingIdentity();
4739 try {
4740 int phoneId = mSubscriptionController.getPhoneId(subId);
4741 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4742 Phone phone = PhoneFactory.getPhone(phoneId);
4743 if (phone != null) {
4744 boolean retVal = phone.isUserDataEnabled();
4745 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4746 return retVal;
4747 } else {
4748 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4749 return false;
4750 }
4751 } finally {
4752 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004753 }
4754 }
4755
4756 /**
4757 * Get whether mobile data is enabled.
4758 *
4759 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4760 * whether mobile data is actually enabled.
4761 *
4762 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4763 *
4764 * @return {@code true} if data is enabled else {@code false}
4765 */
4766 @Override
4767 public boolean isDataEnabled(int subId) {
4768 try {
4769 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4770 null);
4771 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004772 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4773 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004774 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004775
4776 final long identity = Binder.clearCallingIdentity();
4777 try {
4778 int phoneId = mSubscriptionController.getPhoneId(subId);
4779 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4780 Phone phone = PhoneFactory.getPhone(phoneId);
4781 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08004782 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004783 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4784 return retVal;
4785 } else {
4786 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4787 return false;
4788 }
4789 } finally {
4790 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004791 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004792 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004793
4794 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004795 public int getCarrierPrivilegeStatus(int subId) {
4796 final Phone phone = getPhone(subId);
4797 if (phone == null) {
4798 loge("getCarrierPrivilegeStatus: Invalid subId");
4799 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4800 }
4801 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004802 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004803 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004804 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4805 }
4806 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004807 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004808 }
Junda Liu29340342014-07-10 15:23:27 -07004809
4810 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004811 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4812 final Phone phone = getPhone(subId);
4813 if (phone == null) {
4814 loge("getCarrierPrivilegeStatus: Invalid subId");
4815 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4816 }
4817 UiccProfile profile =
4818 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4819 if (profile == null) {
4820 loge("getCarrierPrivilegeStatus: No UICC");
4821 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4822 }
4823 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4824 }
4825
4826 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07004827 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
4828 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08004829 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07004830 }
4831
4832 int phoneId = SubscriptionManager.getPhoneId(subId);
4833 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004834 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07004835 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004836 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4837 }
chen xuf7e9fe82019-05-09 19:31:02 -07004838
4839 return card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004840 }
4841
4842 @Override
4843 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004844 if (TextUtils.isEmpty(pkgName))
4845 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004846 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4847 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4848 UiccCard card = UiccController.getInstance().getUiccCard(i);
4849 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004850 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004851 continue;
4852 }
4853
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004854 result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004855 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4856 break;
4857 }
4858 }
4859
4860 return result;
Junda Liu29340342014-07-10 15:23:27 -07004861 }
Derek Tan89e89d42014-07-08 17:00:10 -07004862
4863 @Override
Junda Liue64de782015-04-16 17:19:16 -07004864 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4865 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4866 loge("phoneId " + phoneId + " is not valid.");
4867 return null;
4868 }
4869 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004870 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004871 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004872 return null ;
4873 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004874 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004875 }
4876
Amith Yamasani6e118872016-02-19 12:53:51 -08004877 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07004878 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004879 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08004880 List<String> privilegedPackages = new ArrayList<>();
4881 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07004882 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
4883 // has UICC in that slot.
4884 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08004885 if (card.hasCarrierPrivilegeRules()) {
4886 if (packages == null) {
4887 // Only check packages in user 0 for now
4888 packages = pm.getInstalledPackagesAsUser(
4889 PackageManager.MATCH_DISABLED_COMPONENTS
chen xuf7e9fe82019-05-09 19:31:02 -07004890 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4891 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08004892 }
4893 for (int p = packages.size() - 1; p >= 0; p--) {
4894 PackageInfo pkgInfo = packages.get(p);
4895 if (pkgInfo != null && pkgInfo.packageName != null
4896 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07004897 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08004898 privilegedPackages.add(pkgInfo.packageName);
4899 }
4900 }
4901 }
4902 }
4903 return privilegedPackages;
4904 }
4905
chen xuf7e9fe82019-05-09 19:31:02 -07004906 @Override
4907 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
4908 List<String> privilegedPackages = new ArrayList<>();
4909 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4910 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
4911 }
4912 return privilegedPackages;
4913 }
4914
Wink Savilleb564aae2014-10-23 10:18:09 -07004915 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004916 final Phone phone = getPhone(subId);
4917 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004918 if (card == null) {
4919 loge("getIccId: No UICC");
4920 return null;
4921 }
4922 String iccId = card.getIccId();
4923 if (TextUtils.isEmpty(iccId)) {
4924 loge("getIccId: ICC ID is null or empty.");
4925 return null;
4926 }
4927 return iccId;
4928 }
4929
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004930 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004931 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4932 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004933 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4934 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004935
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004936 final long identity = Binder.clearCallingIdentity();
4937 try {
4938 final String iccId = getIccId(subId);
4939 final Phone phone = getPhone(subId);
4940 if (phone == null) {
4941 return false;
4942 }
4943 final String subscriberId = phone.getSubscriberId();
4944
4945 if (DBG_MERGE) {
4946 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4947 + subscriberId + " to " + number);
4948 }
4949
4950 if (TextUtils.isEmpty(iccId)) {
4951 return false;
4952 }
4953
4954 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4955
4956 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4957 if (alphaTag == null) {
4958 editor.remove(alphaTagPrefKey);
4959 } else {
4960 editor.putString(alphaTagPrefKey, alphaTag);
4961 }
4962
4963 // Record both the line number and IMSI for this ICCID, since we need to
4964 // track all merged IMSIs based on line number
4965 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4966 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4967 if (number == null) {
4968 editor.remove(numberPrefKey);
4969 editor.remove(subscriberPrefKey);
4970 } else {
4971 editor.putString(numberPrefKey, number);
4972 editor.putString(subscriberPrefKey, subscriberId);
4973 }
4974
4975 editor.commit();
4976 return true;
4977 } finally {
4978 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004979 }
Derek Tan7226c842014-07-02 17:42:23 -07004980 }
4981
4982 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004983 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004984 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004985 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004986 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004987 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004988 return null;
4989 }
Derek Tan97ebb422014-09-05 16:55:38 -07004990
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004991 final long identity = Binder.clearCallingIdentity();
4992 try {
4993 String iccId = getIccId(subId);
4994 if (iccId != null) {
4995 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4996 if (DBG_MERGE) {
4997 log("getLine1NumberForDisplay returning "
4998 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4999 }
5000 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005001 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005002 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5003 return null;
5004 } finally {
5005 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005006 }
Derek Tan7226c842014-07-02 17:42:23 -07005007 }
5008
5009 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005010 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005011 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005012 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005013 return null;
5014 }
Derek Tan97ebb422014-09-05 16:55:38 -07005015
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005016 final long identity = Binder.clearCallingIdentity();
5017 try {
5018 String iccId = getIccId(subId);
5019 if (iccId != null) {
5020 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5021 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5022 }
5023 return null;
5024 } finally {
5025 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005026 }
Derek Tan7226c842014-07-02 17:42:23 -07005027 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005028
5029 @Override
Jordan Liub49b04b2019-05-06 14:45:15 -07005030 public String[] getMergedSubscriberIds(int subId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005031 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5032 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005033 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005034 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
5035 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005036 return null;
5037 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005038
Jordan Liub49b04b2019-05-06 14:45:15 -07005039 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5040 // the process, where TelephonyManager was instantiated.
5041 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005042 final long identity = Binder.clearCallingIdentity();
5043 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005044 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005045 final TelephonyManager tele = TelephonyManager.from(context);
5046 final SubscriptionManager sub = SubscriptionManager.from(context);
5047
5048 // Figure out what subscribers are currently active
5049 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005050
Jordan Liub49b04b2019-05-06 14:45:15 -07005051 // Only consider subs which match the current subId
5052 // This logic can be simplified. See b/131189269 for progress.
5053 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005054 activeSubscriberIds.add(tele.getSubscriberId(subId));
5055 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005056
5057 // First pass, find a number override for an active subscriber
5058 String mergeNumber = null;
5059 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5060 for (String key : prefs.keySet()) {
5061 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5062 final String subscriberId = (String) prefs.get(key);
5063 if (activeSubscriberIds.contains(subscriberId)) {
5064 final String iccId = key.substring(
5065 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5066 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5067 mergeNumber = (String) prefs.get(numberKey);
5068 if (DBG_MERGE) {
5069 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5070 + " for active subscriber " + subscriberId);
5071 }
5072 if (!TextUtils.isEmpty(mergeNumber)) {
5073 break;
5074 }
5075 }
5076 }
5077 }
5078
5079 // Shortcut when no active merged subscribers
5080 if (TextUtils.isEmpty(mergeNumber)) {
5081 return null;
5082 }
5083
5084 // Second pass, find all subscribers under that line override
5085 final ArraySet<String> result = new ArraySet<>();
5086 for (String key : prefs.keySet()) {
5087 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5088 final String number = (String) prefs.get(key);
5089 if (mergeNumber.equals(number)) {
5090 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5091 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5092 final String subscriberId = (String) prefs.get(subscriberKey);
5093 if (!TextUtils.isEmpty(subscriberId)) {
5094 result.add(subscriberId);
5095 }
5096 }
5097 }
5098 }
5099
5100 final String[] resultArray = result.toArray(new String[result.size()]);
5101 Arrays.sort(resultArray);
5102 if (DBG_MERGE) {
5103 Slog.d(LOG_TAG,
5104 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5105 }
5106 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005107 } finally {
5108 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005109 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005110 }
5111
5112 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005113 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005114 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5115 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005116
5117 final long identity = Binder.clearCallingIdentity();
5118 try {
5119 final Phone phone = getPhone(subId);
5120 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5121 } finally {
5122 Binder.restoreCallingIdentity(identity);
5123 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005124 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005125
5126 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005127 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005128 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5129 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005130 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005131
5132 final long identity = Binder.clearCallingIdentity();
5133 try {
5134 final Phone phone = getPhone(subId);
5135 if (phone == null) {
5136 return false;
5137 }
5138 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5139 cdmaNonRoamingList);
5140 } finally {
5141 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005142 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005143 }
5144
5145 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005146 @Deprecated
5147 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5148 enforceModifyPermission();
5149
5150 int returnValue = 0;
5151 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005152 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005153 if(result.exception == null) {
5154 if (result.result != null) {
5155 byte[] responseData = (byte[])(result.result);
5156 if(responseData.length > oemResp.length) {
5157 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5158 responseData.length + "bytes. Buffer Size is " +
5159 oemResp.length + "bytes.");
5160 }
5161 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5162 returnValue = responseData.length;
5163 }
5164 } else {
5165 CommandException ex = (CommandException) result.exception;
5166 returnValue = ex.getCommandError().ordinal();
5167 if(returnValue > 0) returnValue *= -1;
5168 }
5169 } catch (RuntimeException e) {
5170 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5171 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5172 if(returnValue > 0) returnValue *= -1;
5173 }
5174
5175 return returnValue;
5176 }
5177
5178 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005179 public void setRadioCapability(RadioAccessFamily[] rafs) {
5180 try {
5181 ProxyController.getInstance().setRadioCapability(rafs);
5182 } catch (RuntimeException e) {
5183 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5184 }
5185 }
5186
5187 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005188 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005189 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005190 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005191 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005192 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005193 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005194 final long identity = Binder.clearCallingIdentity();
5195 try {
chen xub97461a2018-10-26 14:17:57 -07005196 TelephonyPermissions
5197 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5198 mApp, phone.getSubId(), "getRadioAccessFamily");
5199 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005200 } finally {
5201 Binder.restoreCallingIdentity(identity);
5202 }
chen xub97461a2018-10-26 14:17:57 -07005203 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005204 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005205
5206 @Override
5207 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005208 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005209 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005210
5211 final long identity = Binder.clearCallingIdentity();
5212 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005213 ImsManager.getInstance(defaultPhone.getContext(),
5214 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005215 } finally {
5216 Binder.restoreCallingIdentity(identity);
5217 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005218 }
5219
5220 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005221 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005222 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00005223 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005224 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005225 return false;
5226 }
Svet Ganovb320e182015-04-16 12:30:10 -07005227
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005228 final long identity = Binder.clearCallingIdentity();
5229 try {
5230 // Check the user preference and the system-level IMS setting. Even if the user has
5231 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5232 // In the long run, we may instead need to check if there exists a connection service
5233 // which can support video calling.
5234 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005235 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005236 return imsManager.isVtEnabledByPlatform()
5237 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5238 && imsManager.isVtEnabledByUser();
5239 } finally {
5240 Binder.restoreCallingIdentity(identity);
5241 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005242 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005243
Andrew Leea1239f22015-03-02 17:44:07 -08005244 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005245 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
5246 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5247 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5248 return false;
5249 }
5250
5251 final long identity = Binder.clearCallingIdentity();
5252 try {
5253 CarrierConfigManager configManager =
5254 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005255 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005256 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5257 } finally {
5258 Binder.restoreCallingIdentity(identity);
5259 }
Andrew Leea1239f22015-03-02 17:44:07 -08005260 }
5261
5262 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005263 public boolean isWorldPhone(int subId, String callingPackage) {
5264 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5265 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5266 return false;
5267 }
5268
5269 final long identity = Binder.clearCallingIdentity();
5270 try {
5271 CarrierConfigManager configManager =
5272 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005273 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005274 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5275 } finally {
5276 Binder.restoreCallingIdentity(identity);
5277 }
Andrew Leea1239f22015-03-02 17:44:07 -08005278 }
5279
Andrew Lee9431b832015-03-09 18:46:45 -07005280 @Override
5281 public boolean isTtyModeSupported() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005282 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005283 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005284 }
5285
5286 @Override
5287 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005288 final long identity = Binder.clearCallingIdentity();
5289 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005290 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005291 } finally {
5292 Binder.restoreCallingIdentity(identity);
5293 }
Andrew Lee9431b832015-03-09 18:46:45 -07005294 }
5295
Hall Liuf6668912018-10-31 17:05:23 -07005296 /**
5297 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5298 * support for the feature and device firmware support.
5299 *
5300 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5301 */
5302 @Override
5303 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005304 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005305 final Phone phone = getPhone(subscriptionId);
5306 if (phone == null) {
5307 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5308 return false;
5309 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005310 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005311 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005312 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5313 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005314 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005315 return isCarrierSupported && isDeviceSupported;
5316 } finally {
5317 Binder.restoreCallingIdentity(identity);
5318 }
Hall Liu98187582018-01-22 19:15:32 -08005319 }
5320
Hall Liuf6668912018-10-31 17:05:23 -07005321 /**
5322 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
5323 * both also support RTT.
5324 */
5325 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005326 final long identity = Binder.clearCallingIdentity();
5327 try {
Hall Liuf6668912018-10-31 17:05:23 -07005328 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005329 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005330 } finally {
5331 Binder.restoreCallingIdentity(identity);
5332 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005333 }
5334
Sanket Padawe7310cc72015-01-14 09:53:20 -08005335 /**
5336 * Returns the unique device ID of phone, for example, the IMEI for
5337 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5338 *
5339 * <p>Requires Permission:
5340 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5341 */
5342 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005343 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005344 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005345 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005346 return null;
5347 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005348 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005349 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
5350 callingPackage, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005351 return null;
5352 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005353
5354 final long identity = Binder.clearCallingIdentity();
5355 try {
5356 return phone.getDeviceId();
5357 } finally {
5358 Binder.restoreCallingIdentity(identity);
5359 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005360 }
5361
Ping Sunc67b7c22016-03-02 19:16:45 +08005362 /**
5363 * {@hide}
5364 * Returns the IMS Registration Status on a particular subid
5365 *
5366 * @param subId
5367 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005368 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005369 Phone phone = getPhone(subId);
5370 if (phone != null) {
5371 return phone.isImsRegistered();
5372 } else {
5373 return false;
5374 }
5375 }
5376
Santos Cordon7a1885b2015-02-03 11:15:19 -08005377 @Override
5378 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005379 final long identity = Binder.clearCallingIdentity();
5380 try {
5381 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5382 } finally {
5383 Binder.restoreCallingIdentity(identity);
5384 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005385 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005386
Tyler Gunnf70ed162019-04-03 15:28:53 -07005387 @Override
5388 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5389 final long identity = Binder.clearCallingIdentity();
5390 try {
5391 Phone phone = getPhone(subscriptionId);
5392 if (phone == null) {
5393 return null;
5394 }
5395 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5396 } finally {
5397 Binder.restoreCallingIdentity(identity);
5398 }
5399 }
5400
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005401 /**
5402 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005403 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005404 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005405 final long identity = Binder.clearCallingIdentity();
5406 try {
5407 Phone phone = getPhone(subId);
5408 if (phone != null) {
5409 return phone.isWifiCallingEnabled();
5410 } else {
5411 return false;
5412 }
5413 } finally {
5414 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005415 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005416 }
5417
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005418 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005419 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005420 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005421 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005422 final long identity = Binder.clearCallingIdentity();
5423 try {
5424 Phone phone = getPhone(subId);
5425 if (phone != null) {
5426 return phone.isVideoEnabled();
5427 } else {
5428 return false;
5429 }
5430 } finally {
5431 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005432 }
5433 }
5434
5435 /**
5436 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5437 * defined in {@link ImsRegistrationImplBase}.
5438 */
5439 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005440 final long identity = Binder.clearCallingIdentity();
5441 try {
5442 Phone phone = getPhone(subId);
5443 if (phone != null) {
5444 return phone.getImsRegistrationTech();
5445 } else {
5446 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5447 }
5448 } finally {
5449 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005450 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005451 }
5452
Stuart Scott8eef64f2015-04-08 15:13:54 -07005453 @Override
5454 public void factoryReset(int subId) {
5455 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005456 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5457 return;
5458 }
5459
Svet Ganovcc087f82015-05-12 20:35:54 -07005460 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005461
Svet Ganovcc087f82015-05-12 20:35:54 -07005462 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005463 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5464 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005465 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005466 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005467 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005468 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5469 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005470 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005471 // There has been issues when Sms raw table somehow stores orphan
5472 // fragments. They lead to garbled message when new fragments come
5473 // in and combined with those stale ones. In case this happens again,
5474 // user can reset all network settings which will clean up this table.
5475 cleanUpSmsRawTable(getDefaultPhone().getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07005476 } finally {
5477 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005478 }
5479 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005480
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005481 private void cleanUpSmsRawTable(Context context) {
5482 ContentResolver resolver = context.getContentResolver();
5483 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5484 resolver.delete(uri, null, null);
5485 }
5486
Narayan Kamath1c496c22015-04-16 14:40:19 +01005487 @Override
chen xu5d3637b2019-01-21 23:31:38 -08005488 public String getSimLocaleForSubscriber(int subId) {
5489 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5490 final Phone phone = getPhone(subId);
5491 if (phone == null) {
5492 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08005493 return null;
chen xu5d3637b2019-01-21 23:31:38 -08005494 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005495 final long identity = Binder.clearCallingIdentity();
5496 try {
chen xu5d3637b2019-01-21 23:31:38 -08005497 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5498 phone.getContext().getOpPackageName());
chen xu6291c472019-02-04 12:55:53 -08005499 if (info == null) {
5500 log("getSimLocaleForSubscriber, inactive subId: " + subId);
5501 return null;
5502 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005503 // Try and fetch the locale from the carrier properties or from the SIM language
5504 // preferences (EF-PL and EF-LI)...
5505 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005506 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08005507 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5508 if (localeFromDefaultSim != null) {
5509 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5510 if (DBG) log("Using locale from subId: " + subId + " locale: "
5511 + localeFromDefaultSim);
5512 return localeFromDefaultSim.toLanguageTag();
5513 } else {
5514 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005515 }
5516 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005517
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005518 // The SIM language preferences only store a language (e.g. fr = French), not an
5519 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5520 // the SIM and carrier preferences does not include a country we add the country
5521 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005522 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005523 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08005524 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005525 return mccLocale.toLanguageTag();
5526 }
5527
5528 if (DBG) log("No locale found - returning null");
5529 return null;
5530 } finally {
5531 Binder.restoreCallingIdentity(identity);
5532 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005533 }
5534
5535 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005536 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005537 }
5538
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005539 /**
5540 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5541 */
5542 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005543 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005544 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005545
Chenjie Yu1ba97252018-01-11 18:16:20 -08005546 private final ModemActivityInfo mLastModemActivityInfo =
5547 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
5548
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005549 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005550 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5551 * representing the state of the modem.
5552 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005553 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5554 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005555 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005556 */
5557 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005558 public void requestModemActivityInfo(ResultReceiver result) {
5559 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005560 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005561
5562 final long identity = Binder.clearCallingIdentity();
5563 try {
5564 ModemActivityInfo ret = null;
5565 synchronized (mLastModemActivityInfo) {
5566 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5567 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07005568 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07005569 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005570 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
5571 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005572 mergedTxTimeMs[i] = info.getTxTimeMillis()[i]
5573 + mLastModemActivityInfo.getTxTimeMillis()[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005574 }
5575 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005576 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
5577 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005578 mLastModemActivityInfo.setIdleTimeMillis(
5579 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
5580 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
5581 mLastModemActivityInfo.setRxTimeMillis(
5582 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
5583 mLastModemActivityInfo.setEnergyUsed(
5584 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005585 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005586 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
5587 mLastModemActivityInfo.getSleepTimeMillis(),
5588 mLastModemActivityInfo.getIdleTimeMillis(),
5589 mLastModemActivityInfo.getTxTimeMillis(),
5590 mLastModemActivityInfo.getRxTimeMillis(),
5591 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005592 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005593 Bundle bundle = new Bundle();
5594 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
5595 result.send(0, bundle);
5596 } finally {
5597 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005598 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005599 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005600
Siddharth Rayb8114062018-06-17 15:02:38 -07005601 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
5602 // less than total activity duration.
5603 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
5604 if (info == null) {
5605 return false;
5606 }
5607 int activityDurationMs =
5608 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
5609 int totalTxTimeMs = 0;
5610 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
5611 totalTxTimeMs += info.getTxTimeMillis()[i];
5612 }
5613 return (info.isValid()
5614 && (info.getSleepTimeMillis() <= activityDurationMs)
5615 && (info.getIdleTimeMillis() <= activityDurationMs)
5616 && (info.getRxTimeMillis() <= activityDurationMs)
5617 && (totalTxTimeMs <= activityDurationMs));
5618 }
5619
Jack Yu85bd38a2015-11-09 11:34:32 -08005620 /**
5621 * {@hide}
5622 * Returns the service state information on specified subscription.
5623 */
5624 @Override
5625 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005626 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005627 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08005628 return null;
5629 }
5630
Hall Liuf19c44f2018-11-27 14:38:17 -08005631 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
5632 LocationAccessPolicy.checkLocationPermission(mApp,
5633 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5634 .setCallingPackage(callingPackage)
5635 .setCallingPid(Binder.getCallingPid())
5636 .setCallingUid(Binder.getCallingUid())
5637 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07005638 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005639 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5640 .build());
5641
5642 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
5643 LocationAccessPolicy.checkLocationPermission(mApp,
5644 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5645 .setCallingPackage(callingPackage)
5646 .setCallingPid(Binder.getCallingPid())
5647 .setCallingUid(Binder.getCallingUid())
5648 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07005649 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005650 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5651 .build());
5652 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
5653 boolean hasFinePermission =
5654 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5655 boolean hasCoarsePermission =
5656 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5657
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005658 final long identity = Binder.clearCallingIdentity();
5659 try {
5660 final Phone phone = getPhone(subId);
5661 if (phone == null) {
5662 return null;
5663 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005664
Hall Liuf19c44f2018-11-27 14:38:17 -08005665 ServiceState ss = phone.getServiceState();
5666
5667 // Scrub out the location info in ServiceState depending on what level of access
5668 // the caller has.
5669 if (hasFinePermission) return ss;
5670 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
5671 return ss.sanitizeLocationInfo(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005672 } finally {
5673 Binder.restoreCallingIdentity(identity);
5674 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005675 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005676
5677 /**
5678 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
5679 *
5680 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5681 * voicemail ringtone.
5682 * @return The URI for the ringtone to play when receiving a voicemail from a specific
5683 * PhoneAccount.
5684 */
5685 @Override
5686 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005687 final long identity = Binder.clearCallingIdentity();
5688 try {
5689 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5690 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005691 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005692 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005693
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005694 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
5695 } finally {
5696 Binder.restoreCallingIdentity(identity);
5697 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005698 }
5699
5700 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005701 * Sets the per-account voicemail ringtone.
5702 *
5703 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5704 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5705 *
5706 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5707 * voicemail ringtone.
5708 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5709 * PhoneAccount.
5710 */
5711 @Override
5712 public void setVoicemailRingtoneUri(String callingPackage,
5713 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005714 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005715 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5716 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005717 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005718 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5719 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5720 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005721 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005722
5723 final long identity = Binder.clearCallingIdentity();
5724 try {
5725 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5726 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005727 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005728 }
5729 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5730 } finally {
5731 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005732 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005733 }
5734
5735 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005736 * Returns whether vibration is set for voicemail notification in Phone settings.
5737 *
5738 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5739 * voicemail vibration setting.
5740 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5741 */
5742 @Override
5743 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005744 final long identity = Binder.clearCallingIdentity();
5745 try {
5746 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5747 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005748 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005749 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005750
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005751 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5752 } finally {
5753 Binder.restoreCallingIdentity(identity);
5754 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005755 }
5756
Youhan Wange64578a2016-05-02 15:32:42 -07005757 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005758 * Sets the per-account voicemail vibration.
5759 *
5760 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5761 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5762 *
5763 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5764 * voicemail vibration setting.
5765 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5766 * specific PhoneAccount.
5767 */
5768 @Override
5769 public void setVoicemailVibrationEnabled(String callingPackage,
5770 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005771 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005772 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5773 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005774 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005775 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5776 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5777 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005778 }
5779
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005780 final long identity = Binder.clearCallingIdentity();
5781 try {
5782 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5783 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005784 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005785 }
5786 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5787 } finally {
5788 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005789 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005790 }
5791
5792 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005793 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5794 *
5795 * @throws SecurityException if the caller does not have the required permission
5796 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005797 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005798 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07005799 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005800 }
5801
5802 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005803 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5804 * permission.
5805 *
5806 * @throws SecurityException if the caller does not have the required permission
5807 */
5808 private void enforceSendSmsPermission() {
5809 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5810 }
5811
5812 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005813 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005814 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005815 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005816 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005817 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005818 final long identity = Binder.clearCallingIdentity();
5819 try {
5820 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005821 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005822 if (componentName == null) {
5823 throw new SecurityException(
5824 "Caller not current active visual voicemail package[null]");
5825 }
5826 String vvmPackage = componentName.getPackageName();
5827 if (!callingPackage.equals(vvmPackage)) {
5828 throw new SecurityException("Caller not current active visual voicemail package["
5829 + vvmPackage + "]");
5830 }
5831 } finally {
5832 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005833 }
5834 }
5835
5836 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005837 * Return the application ID for the app type.
5838 *
5839 * @param subId the subscription ID that this request applies to.
5840 * @param appType the uicc app type.
5841 * @return Application ID for specificied app type, or null if no uicc.
5842 */
5843 @Override
5844 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005845 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005846 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005847
5848 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005849 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005850 if (phone == null) {
5851 return null;
5852 }
5853 String aid = null;
5854 try {
5855 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5856 .getApplicationByType(appType).getAid();
5857 } catch (Exception e) {
5858 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5859 }
5860 return aid;
5861 } finally {
5862 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005863 }
Youhan Wange64578a2016-05-02 15:32:42 -07005864 }
5865
Youhan Wang4001d252016-05-11 10:29:41 -07005866 /**
5867 * Return the Electronic Serial Number.
5868 *
5869 * @param subId the subscription ID that this request applies to.
5870 * @return ESN or null if error.
5871 */
5872 @Override
5873 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005874 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005875 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005876
5877 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005878 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005879 if (phone == null) {
5880 return null;
5881 }
5882 String esn = null;
5883 try {
5884 esn = phone.getEsn();
5885 } catch (Exception e) {
5886 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5887 }
5888 return esn;
5889 } finally {
5890 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005891 }
Youhan Wang4001d252016-05-11 10:29:41 -07005892 }
5893
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005894 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005895 * Return the Preferred Roaming List Version.
5896 *
5897 * @param subId the subscription ID that this request applies to.
5898 * @return PRLVersion or null if error.
5899 */
5900 @Override
5901 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005902 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005903 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005904
5905 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005906 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005907 if (phone == null) {
5908 return null;
5909 }
5910 String cdmaPrlVersion = null;
5911 try {
5912 cdmaPrlVersion = phone.getCdmaPrlVersion();
5913 } catch (Exception e) {
5914 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5915 }
5916 return cdmaPrlVersion;
5917 } finally {
5918 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005919 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005920 }
5921
5922 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005923 * Get snapshot of Telephony histograms
5924 * @return List of Telephony histograms
5925 * @hide
5926 */
5927 @Override
5928 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005929 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5930 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005931
5932 final long identity = Binder.clearCallingIdentity();
5933 try {
5934 return RIL.getTelephonyRILTimingHistograms();
5935 } finally {
5936 Binder.restoreCallingIdentity(identity);
5937 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005938 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005939
5940 /**
5941 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08005942 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
5943 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005944 * Require system privileges. In the future we may add this to carrier APIs.
5945 *
Michele Berionne482f8202018-11-27 18:57:59 -08005946 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005947 */
5948 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08005949 @TelephonyManager.SetCarrierRestrictionResult
5950 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005951 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005952 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005953
Michele Berionne482f8202018-11-27 18:57:59 -08005954 if (carrierRestrictionRules == null) {
5955 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08005956 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005957
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005958 final long identity = Binder.clearCallingIdentity();
5959 try {
Michele Berionne482f8202018-11-27 18:57:59 -08005960 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07005961 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005962 } finally {
5963 Binder.restoreCallingIdentity(identity);
5964 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005965 }
5966
5967 /**
5968 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08005969 * Get the allowed carrier list and the excluded carrier list, including the priority between
5970 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005971 * Require system privileges. In the future we may add this to carrier APIs.
5972 *
Michele Berionne482f8202018-11-27 18:57:59 -08005973 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07005974 */
5975 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08005976 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005977 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07005978 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005979
5980 final long identity = Binder.clearCallingIdentity();
5981 try {
Michele Berionne482f8202018-11-27 18:57:59 -08005982 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
5983 if (response instanceof CarrierRestrictionRules) {
5984 return (CarrierRestrictionRules) response;
5985 }
5986 // Response is an Exception of some kind,
5987 // which is signalled to the user as a NULL retval
5988 return null;
5989 } catch (Exception e) {
5990 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
5991 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005992 } finally {
5993 Binder.restoreCallingIdentity(identity);
5994 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005995 }
5996
fionaxu59545b42016-05-25 15:53:37 -07005997 /**
5998 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5999 * @param subId the subscription ID that this action applies to.
6000 * @param enabled control enable or disable metered apns.
6001 * {@hide}
6002 */
6003 @Override
6004 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
6005 enforceModifyPermission();
6006 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006007
6008 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006009 if (phone == null) {
6010 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
6011 return;
6012 }
6013 try {
6014 phone.carrierActionSetMeteredApnsEnabled(enabled);
6015 } catch (Exception e) {
6016 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006017 } finally {
6018 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006019 }
6020 }
6021
6022 /**
6023 * Action set from carrier signalling broadcast receivers to enable/disable radio
6024 * @param subId the subscription ID that this action applies to.
6025 * @param enabled control enable or disable radio.
6026 * {@hide}
6027 */
6028 @Override
6029 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
6030 enforceModifyPermission();
6031 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006032
6033 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006034 if (phone == null) {
6035 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
6036 return;
6037 }
6038 try {
6039 phone.carrierActionSetRadioEnabled(enabled);
6040 } catch (Exception e) {
6041 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006042 } finally {
6043 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006044 }
6045 }
6046
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006047 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006048 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6049 * network status based on which carrier apps could apply actions accordingly,
6050 * enable/disable default url handler for example.
6051 *
6052 * @param subId the subscription ID that this action applies to.
6053 * @param report control start/stop reporting the default network status.
6054 * {@hide}
6055 */
6056 @Override
6057 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6058 enforceModifyPermission();
6059 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006060
6061 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006062 if (phone == null) {
6063 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6064 return;
6065 }
6066 try {
6067 phone.carrierActionReportDefaultNetworkStatus(report);
6068 } catch (Exception e) {
6069 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006070 } finally {
6071 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006072 }
6073 }
6074
6075 /**
fionaxud9622282017-07-17 17:51:30 -07006076 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6077 * @param subId the subscription ID that this action applies to.
6078 * {@hide}
6079 */
6080 @Override
6081 public void carrierActionResetAll(int subId) {
6082 enforceModifyPermission();
6083 final Phone phone = getPhone(subId);
6084 if (phone == null) {
6085 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6086 return;
6087 }
6088 try {
6089 phone.carrierActionResetAll();
6090 } catch (Exception e) {
6091 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6092 }
6093 }
6094
6095 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006096 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6097 * bug report is being generated.
6098 */
6099 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006100 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006101 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6102 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006103 writer.println("Permission Denial: can't dump Phone from pid="
6104 + Binder.getCallingPid()
6105 + ", uid=" + Binder.getCallingUid()
6106 + "without permission "
6107 + android.Manifest.permission.DUMP);
6108 return;
6109 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006110 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006111 }
Jack Yueb89b242016-06-22 13:27:47 -07006112
Brad Ebingerdac2f002018-04-03 15:17:52 -07006113 @Override
6114 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6115 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6116 throws RemoteException {
6117 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
6118 }
6119
Jack Yueb89b242016-06-22 13:27:47 -07006120 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006121 * Get aggregated video call data usage since boot.
6122 *
6123 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6124 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006125 * {@hide}
6126 */
6127 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006128 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006129 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6130 null);
6131
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006132 final long identity = Binder.clearCallingIdentity();
6133 try {
6134 // NetworkStatsService keeps tracking the active network interface and identity. It
6135 // records the delta with the corresponding network identity.
6136 // We just return the total video call data usage snapshot since boot.
6137 Phone phone = getPhone(subId);
6138 if (phone != null) {
6139 return phone.getVtDataUsage(perUidStats);
6140 }
6141 return null;
6142 } finally {
6143 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006144 }
Jack Yueb89b242016-06-22 13:27:47 -07006145 }
Jack Yu75ab2952016-07-08 14:29:33 -07006146
6147 /**
6148 * Policy control of data connection. Usually used when data limit is passed.
6149 * @param enabled True if enabling the data, otherwise disabling.
6150 * @param subId Subscription index
6151 * {@hide}
6152 */
6153 @Override
6154 public void setPolicyDataEnabled(boolean enabled, int subId) {
6155 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006156
6157 final long identity = Binder.clearCallingIdentity();
6158 try {
6159 Phone phone = getPhone(subId);
6160 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006161 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006162 }
6163 } finally {
6164 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006165 }
6166 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006167
6168 /**
6169 * Get Client request stats
6170 * @return List of Client Request Stats
6171 * @hide
6172 */
6173 @Override
6174 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006175 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006176 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006177 return null;
6178 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006179 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006180
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006181 final long identity = Binder.clearCallingIdentity();
6182 try {
6183 if (phone != null) {
6184 return phone.getClientRequestStats();
6185 }
6186
6187 return null;
6188 } finally {
6189 Binder.restoreCallingIdentity(identity);
6190 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006191 }
6192
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006193 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006194 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006195 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006196 }
Jack Yueb4124c2017-02-16 15:32:43 -08006197
6198 /**
Grace Chen70990072017-03-24 17:21:30 -07006199 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006200 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006201 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006202 * @param state State of SIM (power down, power up, pass through)
6203 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6204 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6205 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006206 *
6207 **/
6208 @Override
Grace Chen70990072017-03-24 17:21:30 -07006209 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006210 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006211 Phone phone = PhoneFactory.getPhone(slotIndex);
6212
vagdeviaf9a5b92018-08-15 16:01:53 -07006213 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6214
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006215 final long identity = Binder.clearCallingIdentity();
6216 try {
6217 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006218 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006219 }
6220 } finally {
6221 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006222 }
6223 }
Shuo Qiandd210312017-04-12 22:11:33 +00006224
Tyler Gunn65d45c22017-06-05 11:22:26 -07006225 private boolean isUssdApiAllowed(int subId) {
6226 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006227 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006228 if (configManager == null) {
6229 return false;
6230 }
6231 PersistableBundle pb = configManager.getConfigForSubId(subId);
6232 if (pb == null) {
6233 return false;
6234 }
6235 return pb.getBoolean(
6236 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6237 }
6238
Shuo Qiandd210312017-04-12 22:11:33 +00006239 /**
6240 * Check if phone is in emergency callback mode
6241 * @return true if phone is in emergency callback mode
6242 * @param subId sub id
6243 */
goneil9c5f4872017-12-05 14:07:56 -08006244 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006245 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006246 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006247 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006248
6249 final long identity = Binder.clearCallingIdentity();
6250 try {
6251 if (phone != null) {
6252 return phone.isInEcm();
6253 } else {
6254 return false;
6255 }
6256 } finally {
6257 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006258 }
6259 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006260
6261 /**
6262 * Get the current signal strength information for the given subscription.
6263 * Because this information is not updated when the device is in a low power state
6264 * it should not be relied-upon to be current.
6265 * @param subId Subscription index
6266 * @return the most recent cached signal strength info from the modem
6267 */
6268 @Override
6269 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006270 final long identity = Binder.clearCallingIdentity();
6271 try {
6272 Phone p = getPhone(subId);
6273 if (p == null) {
6274 return null;
6275 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006276
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006277 return p.getSignalStrength();
6278 } finally {
6279 Binder.restoreCallingIdentity(identity);
6280 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006281 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006282
Pengquan Meng77b7f132018-08-22 14:49:57 -07006283 /**
Chen Xuf792fd62018-10-17 17:54:36 +00006284 * Get the current modem radio state for the given slot.
6285 * @param slotIndex slot index.
6286 * @param callingPackage the name of the package making the call.
6287 * @return the current radio power state from the modem
6288 */
6289 @Override
6290 public int getRadioPowerState(int slotIndex, String callingPackage) {
6291 Phone phone = PhoneFactory.getPhone(slotIndex);
6292 if (phone != null) {
6293 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6294 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
6295 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6296 }
6297
6298 final long identity = Binder.clearCallingIdentity();
6299 try {
6300 return phone.getRadioPowerState();
6301 } finally {
6302 Binder.restoreCallingIdentity(identity);
6303 }
6304 }
6305 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6306 }
6307
6308 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07006309 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6310 *
6311 * <p>Requires one of the following permissions:
6312 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6313 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6314 * privileges.
6315 *
6316 * @param subId subscription id
6317 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6318 * {@code false}.
6319 */
6320 @Override
6321 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006322 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6323 null /* message */);
6324
Pengquan Menga1bb6272018-09-06 09:59:22 -07006325 boolean isEnabled = false;
6326 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07006327 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006328 Phone phone = getPhone(subId);
6329 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006330 } catch (Exception e) {
6331 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6332 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07006333 } finally {
6334 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006335 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006336 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006337 }
6338
6339
6340 /**
6341 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6342 *
6343 * <p> Requires permission:
6344 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6345 * privileges.
6346 *
6347 * @param subId subscription id
6348 * @param isEnabled {@code true} means enable, {@code false} means disable.
6349 */
6350 @Override
6351 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006352 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6353 mApp, subId, "setDataRoamingEnabled");
6354
Pengquan Menga1bb6272018-09-06 09:59:22 -07006355 final long identity = Binder.clearCallingIdentity();
6356 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006357 Phone phone = getPhone(subId);
6358 if (phone != null) {
6359 phone.setDataRoamingEnabled(isEnabled);
6360 }
6361 } finally {
6362 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006363 }
6364 }
6365
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006366 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006367 public boolean isManualNetworkSelectionAllowed(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006368 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6369 mApp, subId, "isManualNetworkSelectionAllowed");
6370
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006371 boolean isAllowed = true;
6372 final long identity = Binder.clearCallingIdentity();
6373 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006374 Phone phone = getPhone(subId);
6375 if (phone != null) {
6376 isAllowed = phone.isCspPlmnEnabled();
6377 }
6378 } finally {
6379 Binder.restoreCallingIdentity(identity);
6380 }
6381 return isAllowed;
6382 }
6383
6384 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006385 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006386 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08006387 try {
6388 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07006389 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08006390 } catch (SecurityException e) {
6391 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6392 // has carrier privileges on an active UICC
6393 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6394 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006395 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08006396 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006397 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006398
6399 final long identity = Binder.clearCallingIdentity();
6400 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006401 UiccController uiccController = UiccController.getInstance();
6402 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07006403 if (hasReadPermission) {
6404 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006405 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07006406
6407 // Remove private info if the caller doesn't have access
6408 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6409 for (UiccCardInfo cardInfo : cardInfos) {
6410 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6411 // is available
6412 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
6413 if (card == null || card.getUiccProfile() == null) {
6414 // assume no access if the card or profile is unavailable
6415 filteredInfos.add(cardInfo.getUnprivileged());
6416 continue;
6417 }
6418 UiccProfile profile = card.getUiccProfile();
6419 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6420 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6421 filteredInfos.add(cardInfo);
6422 } else {
6423 filteredInfos.add(cardInfo.getUnprivileged());
6424 }
6425 }
6426 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08006427 } finally {
6428 Binder.restoreCallingIdentity(identity);
6429 }
6430 }
6431
6432 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006433 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006434 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006435
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006436 final long identity = Binder.clearCallingIdentity();
6437 try {
6438 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6439 if (slots == null) {
6440 Rlog.i(LOG_TAG, "slots is null.");
6441 return null;
6442 }
6443
6444 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6445 for (int i = 0; i < slots.length; i++) {
6446 UiccSlot slot = slots[i];
6447 if (slot == null) {
6448 continue;
6449 }
6450
Jordan Liu7be7e652019-05-06 18:55:02 +00006451 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006452 UiccCard card = slot.getUiccCard();
6453 if (card != null) {
6454 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00006455 } else {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006456 cardId = slot.getIccId();
6457 }
6458
Jordan Liu857451f2019-05-09 16:35:35 -07006459 if (cardId != null) {
6460 // if cardId is an ICCID, strip off trailing Fs before exposing to user
6461 // if cardId is an EID, it's all digits so this is fine
6462 cardId = IccUtils.stripTrailingFs(cardId);
6463 }
6464
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006465 int cardState = 0;
6466 switch (slot.getCardState()) {
6467 case CARDSTATE_ABSENT:
6468 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6469 break;
6470 case CARDSTATE_PRESENT:
6471 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6472 break;
6473 case CARDSTATE_ERROR:
6474 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6475 break;
6476 case CARDSTATE_RESTRICTED:
6477 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6478 break;
6479 default:
6480 break;
6481
6482 }
6483
6484 infos[i] = new UiccSlotInfo(
6485 slot.isActive(),
6486 slot.isEuicc(),
6487 cardId,
6488 cardState,
6489 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08006490 slot.isExtendedApduSupported(),
6491 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006492 }
6493 return infos;
6494 } finally {
6495 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006496 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006497 }
6498
6499 @Override
6500 public boolean switchSlots(int[] physicalSlots) {
6501 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006502
6503 final long identity = Binder.clearCallingIdentity();
6504 try {
6505 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6506 } finally {
6507 Binder.restoreCallingIdentity(identity);
6508 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006509 }
Jack Yu4c988042018-02-27 15:30:01 -08006510
6511 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006512 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006513 final long identity = Binder.clearCallingIdentity();
6514 try {
6515 return UiccController.getInstance().getCardIdForDefaultEuicc();
6516 } finally {
6517 Binder.restoreCallingIdentity(identity);
6518 }
6519 }
6520
6521 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006522 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6523 enforceModifyPermission();
6524 final Phone phone = getPhone(subId);
6525 if (phone == null) {
6526 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6527 return;
6528 }
6529
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006530 final long identity = Binder.clearCallingIdentity();
6531 try {
6532 phone.setRadioIndicationUpdateMode(filters, mode);
6533 } finally {
6534 Binder.restoreCallingIdentity(identity);
6535 }
Jack Yu4c988042018-02-27 15:30:01 -08006536 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006537
6538 /**
goneil47ffb6e2018-04-06 15:40:58 -07006539 * A test API to reload the UICC profile.
6540 *
6541 * <p>Requires that the calling app has permission
6542 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6543 * @hide
6544 */
6545 @Override
6546 public void refreshUiccProfile(int subId) {
6547 enforceModifyPermission();
6548
6549 final long identity = Binder.clearCallingIdentity();
6550 try {
6551 Phone phone = getPhone(subId);
6552 if (phone == null) {
6553 return;
6554 }
6555 UiccCard uiccCard = phone.getUiccCard();
6556 if (uiccCard == null) {
6557 return;
6558 }
6559 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6560 if (uiccProfile == null) {
6561 return;
6562 }
6563 uiccProfile.refresh();
6564 } finally {
6565 Binder.restoreCallingIdentity(identity);
6566 }
6567 }
6568
6569 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006570 * Returns false if the mobile data is disabled by default, otherwise return true.
6571 */
6572 private boolean getDefaultDataEnabled() {
6573 return "true".equalsIgnoreCase(
6574 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
6575 }
6576
6577 /**
6578 * Returns true if the data roaming is enabled by default, i.e the system property
6579 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
6580 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
6581 */
6582 private boolean getDefaultDataRoamingEnabled(int subId) {
6583 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006584 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006585 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
6586 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
6587 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
6588 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
6589 return isDataRoamingEnabled;
6590 }
6591
6592 /**
6593 * Returns the default network type for the given {@code subId}, if the default network type is
6594 * not set, return {@link Phone#PREFERRED_NT_MODE}.
6595 */
6596 private int getDefaultNetworkType(int subId) {
6597 return Integer.parseInt(
6598 TelephonyManager.getTelephonyProperty(
6599 mSubscriptionController.getPhoneId(subId),
6600 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
6601 String.valueOf(Phone.PREFERRED_NT_MODE)));
6602 }
fionaxua13278b2018-03-21 00:08:13 -07006603
6604 @Override
6605 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07006606 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07006607 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006608
6609 final long identity = Binder.clearCallingIdentity();
6610 try {
6611 final Phone phone = getPhone(subId);
6612 if (phone == null) {
6613 loge("setCarrierTestOverride fails with invalid subId: " + subId);
6614 return;
6615 }
chen xueaba88a2019-03-15 13:15:10 -07006616 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
6617 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006618 } finally {
6619 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006620 }
fionaxua13278b2018-03-21 00:08:13 -07006621 }
6622
6623 @Override
6624 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006625 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006626
6627 final long identity = Binder.clearCallingIdentity();
6628 try {
6629 final Phone phone = getPhone(subId);
6630 if (phone == null) {
6631 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
6632 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
6633 }
6634 return phone.getCarrierIdListVersion();
6635 } finally {
6636 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006637 }
fionaxua13278b2018-03-21 00:08:13 -07006638 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07006639
6640 @Override
6641 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
6642 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6643 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
6644 return -1;
6645 }
6646
6647 final long identity = Binder.clearCallingIdentity();
6648 try {
6649 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
6650 } finally {
6651 Binder.restoreCallingIdentity(identity);
6652 }
6653 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006654
6655 @Override
6656 public int getCdmaRoamingMode(int subId) {
6657 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6658 mApp, subId, "getCdmaRoamingMode");
6659
6660 final long identity = Binder.clearCallingIdentity();
6661 try {
6662 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
6663 } finally {
6664 Binder.restoreCallingIdentity(identity);
6665 }
6666 }
6667
6668 @Override
6669 public boolean setCdmaRoamingMode(int subId, int mode) {
6670 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6671 mApp, subId, "setCdmaRoamingMode");
6672
6673 final long identity = Binder.clearCallingIdentity();
6674 try {
6675 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
6676 } finally {
6677 Binder.restoreCallingIdentity(identity);
6678 }
6679 }
6680
6681 @Override
6682 public boolean setCdmaSubscriptionMode(int subId, int mode) {
6683 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6684 mApp, subId, "setCdmaSubscriptionMode");
6685
6686 final long identity = Binder.clearCallingIdentity();
6687 try {
6688 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
6689 } finally {
6690 Binder.restoreCallingIdentity(identity);
6691 }
6692 }
Makoto Onukida3bf792018-09-18 16:06:29 -07006693
6694 private void ensureUserRunning(int userId) {
6695 if (!mUserManager.isUserRunning(userId)) {
6696 throw new IllegalStateException("User " + userId + " does not exist or not running");
6697 }
6698 }
6699
6700 /**
6701 * Returns a list of SMS apps on a given user.
6702 *
6703 * Only the shell user (UID 2000 or 0) can call it.
6704 * Target user must be running.
6705 */
6706 @Override
6707 public String[] getSmsApps(int userId) {
6708 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
6709 ensureUserRunning(userId);
6710
6711 final Collection<SmsApplicationData> apps =
6712 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
6713
6714 String[] ret = new String[apps.size()];
6715 int i = 0;
6716 for (SmsApplicationData app : apps) {
6717 ret[i++] = app.mPackageName;
6718 }
6719 return ret;
6720 }
6721
6722 /**
6723 * Returns the default SMS app package name on a given user.
6724 *
6725 * Only the shell user (UID 2000 or 0) can call it.
6726 * Target user must be running.
6727 */
6728 @Override
6729 public String getDefaultSmsApp(int userId) {
6730 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
6731 ensureUserRunning(userId);
6732
6733 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
6734 /* updateIfNeeded= */ true, userId);
6735 return cn == null ? null : cn.getPackageName();
6736 }
6737
6738 /**
6739 * Set a package as the default SMS app on a given user.
6740 *
6741 * Only the shell user (UID 2000 or 0) can call it.
6742 * Target user must be running.
6743 */
6744 @Override
6745 public void setDefaultSmsApp(int userId, String packageName) {
6746 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
6747 ensureUserRunning(userId);
6748
6749 boolean found = false;
6750 for (String pkg : getSmsApps(userId)) {
6751 if (TextUtils.equals(packageName, pkg)) {
6752 found = true;
6753 break;
6754 }
6755 }
6756 if (!found) {
6757 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
6758 }
6759
6760 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
6761 }
sqianc5eccab2018-10-19 18:46:41 -07006762
6763 @Override
sqian8c685422019-02-22 15:55:18 -08006764 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
sqianc5eccab2018-10-19 18:46:41 -07006765 String callingPackage) {
sqian11b7a0e2018-12-05 18:48:28 -08006766 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
sqian8c685422019-02-22 15:55:18 -08006767 mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08006768 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6769 }
6770 final long identity = Binder.clearCallingIdentity();
6771 try {
sqian854d44b2018-12-12 16:48:18 -08006772 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
6773 for (Phone phone: PhoneFactory.getPhones()) {
6774 if (phone.getEmergencyNumberTracker() != null
6775 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
6776 emergencyNumberListInternal.put(
6777 phone.getSubId(),
6778 phone.getEmergencyNumberTracker().getEmergencyNumberList());
6779 }
sqian11b7a0e2018-12-05 18:48:28 -08006780 }
sqian854d44b2018-12-12 16:48:18 -08006781 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08006782 } finally {
6783 Binder.restoreCallingIdentity(identity);
6784 }
sqianc5eccab2018-10-19 18:46:41 -07006785 }
6786
6787 @Override
sqian8c685422019-02-22 15:55:18 -08006788 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006789 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08006790 if (!exactMatch) {
6791 TelephonyPermissions
6792 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08006793 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08006794 }
6795 final long identity = Binder.clearCallingIdentity();
6796 try {
sqian854d44b2018-12-12 16:48:18 -08006797 for (Phone phone: PhoneFactory.getPhones()) {
6798 if (phone.getEmergencyNumberTracker() != null
6799 && phone.getEmergencyNumberTracker() != null) {
6800 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
6801 number, exactMatch)) {
6802 return true;
sqian11b7a0e2018-12-05 18:48:28 -08006803 }
6804 }
sqian11b7a0e2018-12-05 18:48:28 -08006805 }
6806 return false;
6807 } finally {
6808 Binder.restoreCallingIdentity(identity);
6809 }
6810 }
6811
sqianf4ca7ed2019-01-15 18:32:07 -08006812 /**
6813 * Update emergency number list for test mode.
6814 */
6815 @Override
6816 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
6817 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6818 "updateEmergencyNumberListTestMode");
6819
6820 final long identity = Binder.clearCallingIdentity();
6821 try {
6822 for (Phone phone: PhoneFactory.getPhones()) {
6823 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6824 if (tracker != null) {
6825 tracker.executeEmergencyNumberTestModeCommand(action, num);
6826 }
6827 }
6828 } finally {
6829 Binder.restoreCallingIdentity(identity);
6830 }
6831 }
6832
6833 /**
6834 * Get the full emergency number list for test mode.
6835 */
6836 @Override
6837 public List<String> getEmergencyNumberListTestMode() {
6838 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6839 "getEmergencyNumberListTestMode");
6840
6841 final long identity = Binder.clearCallingIdentity();
6842 try {
6843 Set<String> emergencyNumbers = new HashSet<>();
6844 for (Phone phone: PhoneFactory.getPhones()) {
6845 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6846 if (tracker != null) {
6847 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
6848 emergencyNumbers.add(num.getNumber());
6849 }
6850 }
6851 }
6852 return new ArrayList<>(emergencyNumbers);
6853 } finally {
6854 Binder.restoreCallingIdentity(identity);
6855 }
6856 }
6857
chen xud6b45bd2018-10-30 22:27:10 -07006858 @Override
6859 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
6860 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
6861 Phone phone = getPhone(subId);
6862 if (phone == null) {
6863 return null;
6864 }
6865 final long identity = Binder.clearCallingIdentity();
6866 try {
6867 UiccProfile profile = UiccController.getInstance()
6868 .getUiccProfileForPhone(phone.getPhoneId());
6869 if (profile != null) {
6870 return profile.getCertsFromCarrierPrivilegeAccessRules();
6871 }
6872 } finally {
6873 Binder.restoreCallingIdentity(identity);
6874 }
6875 return null;
6876 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08006877
6878 /**
6879 * Enable or disable a modem stack.
6880 */
6881 @Override
6882 public boolean enableModemForSlot(int slotIndex, boolean enable) {
6883 enforceModifyPermission();
6884
6885 final long identity = Binder.clearCallingIdentity();
6886 try {
6887 Phone phone = PhoneFactory.getPhone(slotIndex);
6888 if (phone == null) {
6889 return false;
6890 } else {
6891 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
6892 }
6893 } finally {
6894 Binder.restoreCallingIdentity(identity);
6895 }
6896 }
Michelecea4cf22018-12-21 15:00:11 -08006897
Malcolm Chen4bcd9822019-03-27 18:34:05 -07006898 /**
6899 * Whether a modem stack is enabled or not.
6900 */
6901 @Override
6902 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage) {
6903 Phone phone = PhoneFactory.getPhone(slotIndex);
6904 if (phone == null) return false;
6905
6906 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6907 mApp, phone.getSubId(), callingPackage, "isModemEnabledForSlot")) {
6908 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6909 }
6910
6911 final long identity = Binder.clearCallingIdentity();
6912 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07006913 try {
6914 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
6915 } catch (NoSuchElementException ex) {
6916 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
6917 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07006918 } finally {
6919 Binder.restoreCallingIdentity(identity);
6920 }
6921 }
6922
Michelecea4cf22018-12-21 15:00:11 -08006923 @Override
Michele0ea7d782019-03-19 14:58:42 -07006924 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08006925 enforceModifyPermission();
6926
6927 final long identity = Binder.clearCallingIdentity();
6928 try {
6929 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07006930 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08006931 .commit();
6932 } finally {
6933 Binder.restoreCallingIdentity(identity);
6934 }
6935 }
6936
6937 @Override
Michele0ea7d782019-03-19 14:58:42 -07006938 @TelephonyManager.IsMultiSimSupportedResult
6939 public int isMultiSimSupported(String callingPackage) {
Michele4245e952019-02-04 11:36:23 -08006940 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Michele0ea7d782019-03-19 14:58:42 -07006941 getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) {
6942 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08006943 }
Michelecea4cf22018-12-21 15:00:11 -08006944
6945 final long identity = Binder.clearCallingIdentity();
6946 try {
Michele0ea7d782019-03-19 14:58:42 -07006947 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08006948 } finally {
6949 Binder.restoreCallingIdentity(identity);
6950 }
6951 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006952
Michele0ea7d782019-03-19 14:58:42 -07006953 @TelephonyManager.IsMultiSimSupportedResult
6954 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08006955 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
6956 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
6957 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07006958 loge("isMultiSimSupportedInternal: requires at least 2 cards");
6959 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006960 }
6961 // Check if the hardware supports multisim functionality. If usage of multisim is not
6962 // supported by the modem, indicate that it is restricted.
6963 PhoneCapability staticCapability =
6964 mPhoneConfigurationManager.getStaticPhoneCapability();
6965 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07006966 loge("isMultiSimSupportedInternal: no static configuration available");
6967 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006968 }
6969 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07006970 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
6971 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006972 }
6973 // Check if support of multiple SIMs is restricted by carrier
6974 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07006975 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08006976 }
6977
Michele0ea7d782019-03-19 14:58:42 -07006978 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08006979 }
6980
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006981 /**
6982 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08006983 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
6984 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
6985 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006986 * @param numOfSims number of active sims we want to switch to
6987 */
6988 @Override
6989 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08006990 if (numOfSims == 1) {
6991 enforceModifyPermission();
6992 } else {
6993 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6994 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
6995 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006996 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08006997
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006998 try {
Michele30b57b22019-03-01 12:01:14 -08006999 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07007000 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08007001 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
7002 return;
7003 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007004 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7005 } finally {
7006 Binder.restoreCallingIdentity(identity);
7007 }
7008 }
7009
7010 /**
chen xub4baa772019-04-03 10:23:41 -07007011 * Get whether making changes to modem configurations will trigger reboot.
7012 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007013 */
7014 @Override
chen xub4baa772019-04-03 10:23:41 -07007015 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage) {
7016 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7017 mApp, subId, callingPackage, "doesSwitchMultiSimConfigTriggerReboot")) {
7018 return false;
7019 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007020 final long identity = Binder.clearCallingIdentity();
7021 try {
7022 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
7023 } finally {
7024 Binder.restoreCallingIdentity(identity);
7025 }
7026 }
7027
Nathan Harold29f5f052019-02-15 13:41:57 -08007028 private void updateModemStateMetrics() {
7029 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
7030 // TODO: check the state for each modem if the api is ready.
7031 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
7032 }
7033
Pengquan Meng3889a572019-01-23 11:16:29 -08007034 @Override
7035 public int[] getSlotsMapping() {
7036 enforceReadPrivilegedPermission("getSlotsMapping");
7037
7038 final long identity = Binder.clearCallingIdentity();
7039 try {
7040 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
7041 // All logical slots should have a mapping to a physical slot.
7042 int[] logicalSlotsMapping = new int[phoneCount];
7043 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
7044 for (int i = 0; i < slotInfos.length; i++) {
7045 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
7046 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
7047 }
7048 }
7049 return logicalSlotsMapping;
7050 } finally {
7051 Binder.restoreCallingIdentity(identity);
7052 }
7053 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007054
7055 /**
7056 * Get the IRadio HAL Version
7057 */
7058 @Override
7059 public int getRadioHalVersion() {
7060 Phone phone = getDefaultPhone();
7061 if (phone == null) return -1;
7062 HalVersion hv = phone.getHalVersion();
7063 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7064 return hv.major * 100 + hv.minor;
7065 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007066
7067 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007068 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7069 * corresponding network requests on a subId.
7070 *
7071 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007072 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007073 * 2) APN is un-metered for this subscription, or
7074 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
7075 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on.
7076 *
7077 * @return whether data is allowed for a apn type.
7078 *
7079 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007080 */
7081 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007082 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007083 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Malcolm Chene5ad5792019-04-18 13:51:02 -07007084 mApp, subId, callingPackage, "isDataEnabledForApn")) {
7085 throw new SecurityException("Needs READ_PHONE_STATE for isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007086 }
7087
7088 // Now that all security checks passes, perform the operation as ourselves.
7089 final long identity = Binder.clearCallingIdentity();
7090 try {
7091 Phone phone = getPhone(subId);
7092 if (phone == null) return false;
7093
Jack Yu41407ee2019-05-13 16:54:09 -07007094 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07007095 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7096 } finally {
7097 Binder.restoreCallingIdentity(identity);
7098 }
7099 }
7100
7101 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07007102 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07007103 enforceReadPrivilegedPermission("isApnMetered");
7104
7105 // Now that all security checks passes, perform the operation as ourselves.
7106 final long identity = Binder.clearCallingIdentity();
7107 try {
7108 Phone phone = getPhone(subId);
7109 if (phone == null) return true; // By default return true.
7110
Jack Yu41407ee2019-05-13 16:54:09 -07007111 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007112 } finally {
7113 Binder.restoreCallingIdentity(identity);
7114 }
7115 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007116
7117 @Override
7118 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
7119 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
7120 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
7121 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
7122 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
7123 }
7124 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
7125 Intent intent = new Intent();
7126 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
7127 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7128 // Bring up choose default SMS subscription dialog right now
7129 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
7130 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
7131 mApp.startActivity(intent);
7132 }
chen xud5ca2d52019-05-28 15:20:57 -07007133
7134 @Override
7135 public String getMmsUAProfUrl(int subId) {
7136 //TODO investigate if this API should require proper permission check in R b/133791609
7137 final long identity = Binder.clearCallingIdentity();
7138 try {
7139 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7140 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
7141 } finally {
7142 Binder.restoreCallingIdentity(identity);
7143 }
7144 }
7145
7146 @Override
7147 public String getMmsUserAgent(int subId) {
7148 //TODO investigate if this API should require proper permission check in R b/133791609
7149 final long identity = Binder.clearCallingIdentity();
7150 try {
7151 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7152 .getString(com.android.internal.R.string.config_mms_user_agent);
7153 } finally {
7154 Binder.restoreCallingIdentity(identity);
7155 }
7156 }
Jack Yub07d4972019-05-28 16:12:25 -07007157
7158 @Override
7159 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
7160 enforceModifyPermission();
7161
7162 // Now that all security checks passes, perform the operation as ourselves.
7163 final long identity = Binder.clearCallingIdentity();
7164 try {
7165 Phone phone = getPhone(subId);
7166 if (phone == null) return false;
7167
7168 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
7169 } finally {
7170 Binder.restoreCallingIdentity(identity);
7171 }
7172 }
7173
7174 @Override
7175 public boolean isDataAllowedInVoiceCall(int subId) {
7176 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
7177
7178 // Now that all security checks passes, perform the operation as ourselves.
7179 final long identity = Binder.clearCallingIdentity();
7180 try {
7181 Phone phone = getPhone(subId);
7182 if (phone == null) return false;
7183
7184 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
7185 } finally {
7186 Binder.restoreCallingIdentity(identity);
7187 }
7188 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07007189
7190 /**
7191 * Updates whether conference event pacakge handling is enabled.
7192 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
7193 * otherwise.
7194 */
7195 @Override
7196 public void setCepEnabled(boolean isCepEnabled) {
7197 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
7198
7199 final long identity = Binder.clearCallingIdentity();
7200 try {
7201 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
7202 for (Phone phone : PhoneFactory.getPhones()) {
7203 Phone defaultPhone = phone.getImsPhone();
7204 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7205 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7206 ImsPhoneCallTracker imsPhoneCallTracker =
7207 (ImsPhoneCallTracker) imsPhone.getCallTracker();
7208 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
7209 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
7210 + imsPhone.getMsisdn());
7211 }
7212 }
7213 } finally {
7214 Binder.restoreCallingIdentity(identity);
7215 }
7216 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007217}