blob: b0f8c5f025f7bd5902b237d304416828969bf6aa [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Ta-wei Yen87c49842016-05-13 21:19:52 -070021import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
22
Ta-wei Yen30a69c82016-12-27 14:52:32 -080023import android.Manifest.permission;
Tyler Gunnf70ed162019-04-03 15:28:53 -070024import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070025import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080026import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070027import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070028import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070029import android.content.Context;
30import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070031import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070032import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070033import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080034import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070035import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070036import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070037import android.net.Uri;
38import android.os.AsyncResult;
39import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080040import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070041import android.os.Bundle;
42import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070043import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070044import android.os.Looper;
45import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070046import android.os.Messenger;
Tyler Gunn65d45c22017-06-05 11:22:26 -070047import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080048import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070049import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070050import android.os.ServiceManager;
Brad Ebingerdac2f002018-04-03 15:17:52 -070051import android.os.ShellCallback;
Pengquan Meng85728fb2018-03-12 16:31:21 -070052import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070053import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070054import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070055import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070056import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080057import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070058import android.provider.Telephony;
Santos Cordon7a1885b2015-02-03 11:15:19 -080059import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080060import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070061import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070062import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080063import android.telephony.CarrierRestrictionRules;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070064import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070065import android.telephony.CellInfoGsm;
66import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070067import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070068import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070069import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070070import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080071import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070072import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080073import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070074import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080075import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080076import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070077import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080078import android.telephony.RadioAccessSpecifier;
Tyler Gunn65d45c22017-06-05 11:22:26 -070079import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070080import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080081import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080082import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080083import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070084import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070085import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080086import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080087import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000088import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070089import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070090import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070091import android.telephony.cdma.CdmaCellLocation;
Jack Yub5d8f642018-11-26 11:20:48 -080092import android.telephony.data.ApnSetting;
Jack Yu41407ee2019-05-13 16:54:09 -070093import android.telephony.data.ApnSetting.ApnType;
Jack Yub5d8f642018-11-26 11:20:48 -080094import android.telephony.emergency.EmergencyNumber;
Nathan Harold3ff88932018-08-14 10:19:49 -070095import android.telephony.gsm.GsmCellLocation;
Brad Ebinger1c8542e2019-01-14 13:43:14 -080096import android.telephony.ims.ProvisioningManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -070097import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080098import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -070099import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800100import android.telephony.ims.aidl.IImsMmTelFeature;
101import android.telephony.ims.aidl.IImsRcsFeature;
102import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700103import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800104import android.telephony.ims.feature.MmTelFeature;
105import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800106import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700107import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800108import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700109import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800110import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800111import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800112
Brad Ebinger35c841c2018-10-01 10:40:55 -0700113import com.android.ims.ImsException;
Andrew Lee312e8172014-10-23 17:01:36 -0700114import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800115import com.android.ims.internal.IImsServiceFeatureCallback;
Jordan Liua39e6c12020-03-04 13:59:23 -0800116import com.android.internal.annotations.VisibleForTesting;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700117import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700118import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700119import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800120import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700121import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700122import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700123import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800124import com.android.internal.telephony.HalVersion;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700125import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800126import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700127import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800128import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700129import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100130import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700131import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700132import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700133import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700134import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800135import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700136import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700137import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700138import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700139import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700140import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700141import com.android.internal.telephony.ServiceStateTracker;
Makoto Onukida3bf792018-09-18 16:06:29 -0700142import com.android.internal.telephony.SmsApplication;
143import com.android.internal.telephony.SmsApplication.SmsApplicationData;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700144import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700145import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800146import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800147import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700148import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800149import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700150import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800151import com.android.internal.telephony.ims.ImsResolver;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800152import com.android.internal.telephony.metrics.TelephonyMetrics;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700153import com.android.internal.telephony.uicc.IccIoResult;
154import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800155import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700156import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800157import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700158import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800159import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000160import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700161import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800162import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700163import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700164import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800165import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700166import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700167import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800168
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700169import java.io.FileDescriptor;
170import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700171import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800172import java.util.Arrays;
Makoto Onukida3bf792018-09-18 16:06:29 -0700173import java.util.Collection;
sqian11b7a0e2018-12-05 18:48:28 -0800174import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800175import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800176import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100177import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800178import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700179import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800180import java.util.Set;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700181
182/**
183 * Implementation of the ITelephony interface.
184 */
Santos Cordon117fee72014-05-16 17:56:12 -0700185public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700186 private static final String LOG_TAG = "PhoneInterfaceManager";
187 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
188 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800189 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700190
191 // Message codes used with mMainThreadHandler
192 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700193 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
194 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700195 private static final int CMD_OPEN_CHANNEL = 9;
196 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
197 private static final int CMD_CLOSE_CHANNEL = 11;
198 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800199 private static final int CMD_NV_READ_ITEM = 13;
200 private static final int EVENT_NV_READ_ITEM_DONE = 14;
201 private static final int CMD_NV_WRITE_ITEM = 15;
202 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
203 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
204 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700205 private static final int CMD_RESET_MODEM_CONFIG = 19;
206 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800207 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
208 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
209 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
210 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800211 private static final int CMD_SEND_ENVELOPE = 25;
212 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000213 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
214 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700215 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
216 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
217 private static final int CMD_EXCHANGE_SIM_IO = 31;
218 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800219 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
220 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700221 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
222 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700223 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
224 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700225 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
226 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
227 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
228 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700229 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
230 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
231 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
232 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700233 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800234 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
235 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000236 private static final int CMD_SWITCH_SLOTS = 50;
237 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700238 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
239 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
240 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
241 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
242 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
243 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
244 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
245 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700246 private static final int CMD_GET_ALL_CELL_INFO = 60;
247 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
248 private static final int CMD_GET_CELL_LOCATION = 62;
249 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700250 private static final int CMD_MODEM_REBOOT = 64;
251 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700252 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
253 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800254 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
255 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700256 private static final int CMD_GET_MODEM_STATUS = 70;
257 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700258
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800259 // Parameters of select command.
260 private static final int SELECT_COMMAND = 0xA4;
261 private static final int SELECT_P1 = 0x04;
262 private static final int SELECT_P2 = 0;
263 private static final int SELECT_P3 = 0x10;
264
Pengquan Meng85728fb2018-03-12 16:31:21 -0700265 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
266 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
267 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
268
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700269 /** The singleton instance. */
270 private static PhoneInterfaceManager sInstance;
271
Wink Saville3ab207e2014-11-20 13:07:20 -0800272 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800273 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700274 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800275 private AppOpsManager mAppOps;
276 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800277 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800278 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700279 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700280
Derek Tan97ebb422014-09-05 16:55:38 -0700281 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
282 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800283 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800284 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700285
Michelecea4cf22018-12-21 15:00:11 -0800286 // String to store multi SIM allowed
287 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
288
Derek Tan740e1672017-06-27 14:56:27 -0700289 // The AID of ISD-R.
290 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
291
yinxub1bed742017-04-17 11:45:04 -0700292 private NetworkScanRequestTracker mNetworkScanRequestTracker;
293
David Kelly5e06a7f2018-03-12 14:10:59 +0000294 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
295 private static final int MANUFACTURER_CODE_LENGTH = 8;
296
Derek Tan89e89d42014-07-08 17:00:10 -0700297 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700298 * A request object to use for transmitting data to an ICC.
299 */
300 private static final class IccAPDUArgument {
301 public int channel, cla, command, p1, p2, p3;
302 public String data;
303
304 public IccAPDUArgument(int channel, int cla, int command,
305 int p1, int p2, int p3, String data) {
306 this.channel = channel;
307 this.cla = cla;
308 this.command = command;
309 this.p1 = p1;
310 this.p2 = p2;
311 this.p3 = p3;
312 this.data = data;
313 }
314 }
315
316 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700317 * A request object to use for transmitting data to an ICC.
318 */
319 private static final class ManualNetworkSelectionArgument {
320 public OperatorInfo operatorInfo;
321 public boolean persistSelection;
322
323 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
324 this.operatorInfo = operatorInfo;
325 this.persistSelection = persistSelection;
326 }
327 }
328
329 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700330 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
331 * request after sending. The main thread will notify the request when it is complete.
332 */
333 private static final class MainThreadRequest {
334 /** The argument to use for the request */
335 public Object argument;
336 /** The result of the request that is run on the main thread */
337 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800338 // The subscriber id that this request applies to. Defaults to
339 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
340 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700341
Nathan Harold92bed182018-10-12 18:16:49 -0700342 // In cases where subId is unavailable, the caller needs to specify the phone.
343 public Phone phone;
344
vagdeviaf9a5b92018-08-15 16:01:53 -0700345 public WorkSource workSource;
346
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700347 public MainThreadRequest(Object argument) {
348 this.argument = argument;
349 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800350
Nathan Harold92bed182018-10-12 18:16:49 -0700351 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
352 this.argument = argument;
353 if (phone != null) {
354 this.phone = phone;
355 }
356 this.workSource = workSource;
357 }
358
vagdeviaf9a5b92018-08-15 16:01:53 -0700359 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800360 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800361 if (subId != null) {
362 this.subId = subId;
363 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700364 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800365 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700366 }
367
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800368 private static final class IncomingThirdPartyCallArgs {
369 public final ComponentName component;
370 public final String callId;
371 public final String callerDisplayName;
372
373 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
374 String callerDisplayName) {
375 this.component = component;
376 this.callId = callId;
377 this.callerDisplayName = callerDisplayName;
378 }
379 }
380
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700381 /**
382 * A handler that processes messages on the main thread in the phone process. Since many
383 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
384 * inbound binder threads to the main thread in the phone process. The Binder thread
385 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
386 * on, which will be notified when the operation completes and will contain the result of the
387 * request.
388 *
389 * <p>If a MainThreadRequest object is provided in the msg.obj field,
390 * note that request.result must be set to something non-null for the calling thread to
391 * unblock.
392 */
393 private final class MainThreadHandler extends Handler {
394 @Override
395 public void handleMessage(Message msg) {
396 MainThreadRequest request;
397 Message onCompleted;
398 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800399 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700400 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800401 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700402
403 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700404 case CMD_HANDLE_USSD_REQUEST: {
405 request = (MainThreadRequest) msg.obj;
406 final Phone phone = getPhoneFromRequest(request);
407 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
408 String ussdRequest = ussdObject.first;
409 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700410
Pengquan Menga1bb6272018-09-06 09:59:22 -0700411 if (!isUssdApiAllowed(request.subId)) {
412 // Carrier does not support use of this API, return failure.
413 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
414 UssdResponse response = new UssdResponse(ussdRequest, null);
415 Bundle returnData = new Bundle();
416 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
417 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700418
Pengquan Menga1bb6272018-09-06 09:59:22 -0700419 request.result = true;
420 notifyRequester(request);
421 return;
422 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700423
Pengquan Menga1bb6272018-09-06 09:59:22 -0700424 try {
425 request.result = phone != null
426 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
427 } catch (CallStateException cse) {
428 request.result = false;
429 }
430 // Wake up the requesting thread
431 notifyRequester(request);
432 break;
pkanwar32d516d2016-10-14 19:37:38 -0700433 }
434
Yorke Lee716f67e2015-06-17 15:39:16 -0700435 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700436 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700437 final Phone phone = getPhoneFromRequest(request);
438 request.result = phone != null ?
439 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
440 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700441 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700442 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700443 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700444 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700445
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700446 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700447 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700448 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800449 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700450 if (uiccCard == null) {
451 loge("iccTransmitApduLogicalChannel: No UICC");
452 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700453 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700454 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700455 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
456 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700457 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700458 iccArgument.channel, iccArgument.cla, iccArgument.command,
459 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700460 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700461 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700462 break;
463
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700464 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700465 ar = (AsyncResult) msg.obj;
466 request = (MainThreadRequest) ar.userObj;
467 if (ar.exception == null && ar.result != null) {
468 request.result = ar.result;
469 } else {
470 request.result = new IccIoResult(0x6F, 0, (byte[])null);
471 if (ar.result == null) {
472 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800473 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700474 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800475 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700476 } else {
477 loge("iccTransmitApduLogicalChannel: Unknown exception");
478 }
479 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700480 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700481 break;
482
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700483 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
484 request = (MainThreadRequest) msg.obj;
485 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800486 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700487 if (uiccCard == null) {
488 loge("iccTransmitApduBasicChannel: No UICC");
489 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700490 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700491 } else {
492 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
493 request);
494 uiccCard.iccTransmitApduBasicChannel(
495 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
496 iccArgument.p3, iccArgument.data, onCompleted);
497 }
498 break;
499
500 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
501 ar = (AsyncResult) msg.obj;
502 request = (MainThreadRequest) ar.userObj;
503 if (ar.exception == null && ar.result != null) {
504 request.result = ar.result;
505 } else {
506 request.result = new IccIoResult(0x6F, 0, (byte[])null);
507 if (ar.result == null) {
508 loge("iccTransmitApduBasicChannel: Empty response");
509 } else if (ar.exception instanceof CommandException) {
510 loge("iccTransmitApduBasicChannel: CommandException: " +
511 ar.exception);
512 } else {
513 loge("iccTransmitApduBasicChannel: Unknown exception");
514 }
515 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700516 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700517 break;
518
519 case CMD_EXCHANGE_SIM_IO:
520 request = (MainThreadRequest) msg.obj;
521 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800522 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700523 if (uiccCard == null) {
524 loge("iccExchangeSimIO: No UICC");
525 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700526 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700527 } else {
528 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
529 request);
530 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
531 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
532 iccArgument.data, onCompleted);
533 }
534 break;
535
536 case EVENT_EXCHANGE_SIM_IO_DONE:
537 ar = (AsyncResult) msg.obj;
538 request = (MainThreadRequest) ar.userObj;
539 if (ar.exception == null && ar.result != null) {
540 request.result = ar.result;
541 } else {
542 request.result = new IccIoResult(0x6f, 0, (byte[])null);
543 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700544 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700545 break;
546
Derek Tan4d5e5c12014-02-04 11:54:58 -0800547 case CMD_SEND_ENVELOPE:
548 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800549 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700550 if (uiccCard == null) {
551 loge("sendEnvelopeWithStatus: No UICC");
552 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700553 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700554 } else {
555 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
556 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
557 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800558 break;
559
560 case EVENT_SEND_ENVELOPE_DONE:
561 ar = (AsyncResult) msg.obj;
562 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700563 if (ar.exception == null && ar.result != null) {
564 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800565 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700566 request.result = new IccIoResult(0x6F, 0, (byte[])null);
567 if (ar.result == null) {
568 loge("sendEnvelopeWithStatus: Empty response");
569 } else if (ar.exception instanceof CommandException) {
570 loge("sendEnvelopeWithStatus: CommandException: " +
571 ar.exception);
572 } else {
573 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
574 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800575 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700576 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800577 break;
578
Shishir Agrawal566b7612013-10-28 14:41:00 -0700579 case CMD_OPEN_CHANNEL:
580 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800581 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800582 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700583 if (uiccCard == null) {
584 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800585 request.result = new IccOpenLogicalChannelResponse(-1,
586 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700587 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700588 } else {
589 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800590 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
591 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700592 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700593 break;
594
595 case EVENT_OPEN_CHANNEL_DONE:
596 ar = (AsyncResult) msg.obj;
597 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700598 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700599 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700600 int[] result = (int[]) ar.result;
601 int channelId = result[0];
602 byte[] selectResponse = null;
603 if (result.length > 1) {
604 selectResponse = new byte[result.length - 1];
605 for (int i = 1; i < result.length; ++i) {
606 selectResponse[i - 1] = (byte) result[i];
607 }
608 }
609 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700610 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700611 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700612 if (ar.result == null) {
613 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700614 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700615 if (ar.exception != null) {
616 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
617 }
618
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700619 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700620 if (ar.exception instanceof CommandException) {
621 CommandException.Error error =
622 ((CommandException) (ar.exception)).getCommandError();
623 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700624 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700625 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700626 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700627 }
628 }
629 openChannelResp = new IccOpenLogicalChannelResponse(
630 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700631 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700632 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700633 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700634 break;
635
636 case CMD_CLOSE_CHANNEL:
637 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800638 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700639 if (uiccCard == null) {
640 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900641 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700642 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700643 } else {
644 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
645 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
646 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700647 break;
648
649 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800650 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
651 break;
652
653 case CMD_NV_READ_ITEM:
654 request = (MainThreadRequest) msg.obj;
655 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800656 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
657 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800658 break;
659
660 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700661 ar = (AsyncResult) msg.obj;
662 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800663 if (ar.exception == null && ar.result != null) {
664 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700665 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800666 request.result = "";
667 if (ar.result == null) {
668 loge("nvReadItem: Empty response");
669 } else if (ar.exception instanceof CommandException) {
670 loge("nvReadItem: CommandException: " +
671 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700672 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800673 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700674 }
675 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700676 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700677 break;
678
Jake Hambye994d462014-02-03 13:10:13 -0800679 case CMD_NV_WRITE_ITEM:
680 request = (MainThreadRequest) msg.obj;
681 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
682 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800683 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700684 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800685 break;
686
687 case EVENT_NV_WRITE_ITEM_DONE:
688 handleNullReturnEvent(msg, "nvWriteItem");
689 break;
690
691 case CMD_NV_WRITE_CDMA_PRL:
692 request = (MainThreadRequest) msg.obj;
693 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800694 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800695 break;
696
697 case EVENT_NV_WRITE_CDMA_PRL_DONE:
698 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
699 break;
700
chen xu6dac5ab2018-10-26 17:39:23 -0700701 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800702 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700703 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800704 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800705 break;
706
chen xu6dac5ab2018-10-26 17:39:23 -0700707 case EVENT_RESET_MODEM_CONFIG_DONE:
708 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800709 break;
710
Jake Hamby7c27be32014-03-03 13:25:59 -0800711 case CMD_GET_PREFERRED_NETWORK_TYPE:
712 request = (MainThreadRequest) msg.obj;
713 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700714 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800715 break;
716
717 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
718 ar = (AsyncResult) msg.obj;
719 request = (MainThreadRequest) ar.userObj;
720 if (ar.exception == null && ar.result != null) {
721 request.result = ar.result; // Integer
722 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800723 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800724 if (ar.result == null) {
725 loge("getPreferredNetworkType: Empty response");
726 } else if (ar.exception instanceof CommandException) {
727 loge("getPreferredNetworkType: CommandException: " +
728 ar.exception);
729 } else {
730 loge("getPreferredNetworkType: Unknown exception");
731 }
732 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700733 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800734 break;
735
736 case CMD_SET_PREFERRED_NETWORK_TYPE:
737 request = (MainThreadRequest) msg.obj;
738 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
739 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700740 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800741 break;
742
743 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
744 handleNullReturnEvent(msg, "setPreferredNetworkType");
745 break;
746
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000747 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
748 request = (MainThreadRequest)msg.obj;
749 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800750 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000751 break;
752
753 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
754 ar = (AsyncResult)msg.obj;
755 request = (MainThreadRequest)ar.userObj;
756 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700757 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000758 break;
759
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800760 case CMD_SET_VOICEMAIL_NUMBER:
761 request = (MainThreadRequest) msg.obj;
762 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
763 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800764 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
765 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800766 break;
767
768 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
769 handleNullReturnEvent(msg, "setVoicemailNumber");
770 break;
771
Stuart Scott54788802015-03-30 13:18:01 -0700772 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
773 request = (MainThreadRequest) msg.obj;
774 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
775 request);
776 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
777 break;
778
779 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
780 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
781 break;
782
Shishir Agrawal302c8692015-06-19 13:49:39 -0700783 case CMD_PERFORM_NETWORK_SCAN:
784 request = (MainThreadRequest) msg.obj;
785 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
786 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
787 break;
788
789 case EVENT_PERFORM_NETWORK_SCAN_DONE:
790 ar = (AsyncResult) msg.obj;
791 request = (MainThreadRequest) ar.userObj;
792 CellNetworkScanResult cellScanResult;
793 if (ar.exception == null && ar.result != null) {
794 cellScanResult = new CellNetworkScanResult(
795 CellNetworkScanResult.STATUS_SUCCESS,
796 (List<OperatorInfo>) ar.result);
797 } else {
798 if (ar.result == null) {
799 loge("getCellNetworkScanResults: Empty response");
800 }
801 if (ar.exception != null) {
802 loge("getCellNetworkScanResults: Exception: " + ar.exception);
803 }
804 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
805 if (ar.exception instanceof CommandException) {
806 CommandException.Error error =
807 ((CommandException) (ar.exception)).getCommandError();
808 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
809 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
810 } else if (error == CommandException.Error.GENERIC_FAILURE) {
811 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
812 }
813 }
814 cellScanResult = new CellNetworkScanResult(errorCode, null);
815 }
816 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700817 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700818 break;
819
820 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
821 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700822 ManualNetworkSelectionArgument selArg =
823 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700824 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
825 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700826 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
827 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700828 break;
829
830 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700831 ar = (AsyncResult) msg.obj;
832 request = (MainThreadRequest) ar.userObj;
833 if (ar.exception == null) {
834 request.result = true;
835 } else {
836 request.result = false;
837 loge("setNetworkSelectionModeManual " + ar.exception);
838 }
839 notifyRequester(request);
840 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700841 break;
842
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700843 case CMD_GET_MODEM_ACTIVITY_INFO:
844 request = (MainThreadRequest) msg.obj;
845 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -0700846 if (defaultPhone != null) {
847 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
848 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700849 break;
850
851 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
852 ar = (AsyncResult) msg.obj;
853 request = (MainThreadRequest) ar.userObj;
854 if (ar.exception == null && ar.result != null) {
855 request.result = ar.result;
856 } else {
857 if (ar.result == null) {
858 loge("queryModemActivityInfo: Empty response");
859 } else if (ar.exception instanceof CommandException) {
860 loge("queryModemActivityInfo: CommandException: " +
861 ar.exception);
862 } else {
863 loge("queryModemActivityInfo: Unknown exception");
864 }
865 }
Amit Mahajand4766222016-01-28 15:28:28 -0800866 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
867 if (request.result == null) {
868 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
869 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700870 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700871 break;
872
Meng Wang1a7c35a2016-05-05 20:56:15 -0700873 case CMD_SET_ALLOWED_CARRIERS:
874 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -0800875 CarrierRestrictionRules argument =
876 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700877 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -0800878 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700879 break;
880
881 case EVENT_SET_ALLOWED_CARRIERS_DONE:
882 ar = (AsyncResult) msg.obj;
883 request = (MainThreadRequest) ar.userObj;
884 if (ar.exception == null && ar.result != null) {
885 request.result = ar.result;
886 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800887 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
888 if (ar.exception instanceof CommandException) {
889 loge("setAllowedCarriers: CommandException: " + ar.exception);
890 CommandException.Error error =
891 ((CommandException) (ar.exception)).getCommandError();
892 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
893 request.result =
894 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
895 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700896 } else {
897 loge("setAllowedCarriers: Unknown exception");
898 }
899 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700900 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700901 break;
902
903 case CMD_GET_ALLOWED_CARRIERS:
904 request = (MainThreadRequest) msg.obj;
905 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800906 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700907 break;
908
909 case EVENT_GET_ALLOWED_CARRIERS_DONE:
910 ar = (AsyncResult) msg.obj;
911 request = (MainThreadRequest) ar.userObj;
912 if (ar.exception == null && ar.result != null) {
913 request.result = ar.result;
914 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800915 request.result = new IllegalStateException(
916 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700917 if (ar.result == null) {
918 loge("getAllowedCarriers: Empty response");
919 } else if (ar.exception instanceof CommandException) {
920 loge("getAllowedCarriers: CommandException: " +
921 ar.exception);
922 } else {
923 loge("getAllowedCarriers: Unknown exception");
924 }
925 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700926 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700927 break;
928
Nathan Haroldb3014052017-01-25 15:57:32 -0800929 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
930 ar = (AsyncResult) msg.obj;
931 request = (MainThreadRequest) ar.userObj;
932 if (ar.exception == null && ar.result != null) {
933 request.result = ar.result;
934 } else {
935 request.result = new IllegalArgumentException(
936 "Failed to retrieve Forbidden Plmns");
937 if (ar.result == null) {
938 loge("getForbiddenPlmns: Empty response");
939 } else {
940 loge("getForbiddenPlmns: Unknown exception");
941 }
942 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700943 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800944 break;
945
946 case CMD_GET_FORBIDDEN_PLMNS:
947 request = (MainThreadRequest) msg.obj;
948 uiccCard = getUiccCardFromRequest(request);
949 if (uiccCard == null) {
950 loge("getForbiddenPlmns() UiccCard is null");
951 request.result = new IllegalArgumentException(
952 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700953 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800954 break;
955 }
956 Integer appType = (Integer) request.argument;
957 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
958 if (uiccApp == null) {
959 loge("getForbiddenPlmns() no app with specified type -- "
960 + appType);
961 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700962 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800963 break;
964 } else {
965 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
966 + " specified type -- " + appType);
967 }
968 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
969 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
970 onCompleted);
971 break;
972
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000973 case CMD_SWITCH_SLOTS:
974 request = (MainThreadRequest) msg.obj;
975 int[] physicalSlots = (int[]) request.argument;
976 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
977 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
978 break;
979
980 case EVENT_SWITCH_SLOTS_DONE:
981 ar = (AsyncResult) msg.obj;
982 request = (MainThreadRequest) ar.userObj;
983 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700984 notifyRequester(request);
985 break;
986 case CMD_GET_NETWORK_SELECTION_MODE:
987 request = (MainThreadRequest) msg.obj;
988 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
989 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
990 break;
991
992 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
993 ar = (AsyncResult) msg.obj;
994 request = (MainThreadRequest) ar.userObj;
995 if (ar.exception != null) {
996 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
997 } else {
998 int mode = ((int[]) ar.result)[0];
999 if (mode == 0) {
1000 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1001 } else {
1002 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1003 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001004 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001005 notifyRequester(request);
1006 break;
1007 case CMD_GET_CDMA_ROAMING_MODE:
1008 request = (MainThreadRequest) msg.obj;
1009 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1010 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1011 break;
1012 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1013 ar = (AsyncResult) msg.obj;
1014 request = (MainThreadRequest) ar.userObj;
1015 if (ar.exception != null) {
1016 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1017 } else {
1018 request.result = ((int[]) ar.result)[0];
1019 }
1020 notifyRequester(request);
1021 break;
1022 case CMD_SET_CDMA_ROAMING_MODE:
1023 request = (MainThreadRequest) msg.obj;
1024 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1025 int mode = (int) request.argument;
1026 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1027 break;
1028 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1029 ar = (AsyncResult) msg.obj;
1030 request = (MainThreadRequest) ar.userObj;
1031 request.result = ar.exception == null;
1032 notifyRequester(request);
1033 break;
1034 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1035 request = (MainThreadRequest) msg.obj;
1036 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1037 int subscriptionMode = (int) request.argument;
1038 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1039 break;
1040 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1041 ar = (AsyncResult) msg.obj;
1042 request = (MainThreadRequest) ar.userObj;
1043 request.result = ar.exception == null;
1044 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001045 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001046 case CMD_GET_ALL_CELL_INFO:
1047 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001048 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001049 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001050 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001051 case EVENT_GET_ALL_CELL_INFO_DONE:
1052 ar = (AsyncResult) msg.obj;
1053 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001054 // If a timeout occurs, the response will be null
1055 request.result = (ar.exception == null && ar.result != null)
1056 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001057 synchronized (request) {
1058 request.notifyAll();
1059 }
1060 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001061 case CMD_REQUEST_CELL_INFO_UPDATE:
1062 request = (MainThreadRequest) msg.obj;
1063 request.phone.requestCellInfoUpdate(request.workSource,
1064 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1065 break;
1066 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1067 ar = (AsyncResult) msg.obj;
1068 request = (MainThreadRequest) ar.userObj;
1069 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1070 try {
1071 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001072 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Nathan Harolde82c4b82018-12-18 19:40:37 -08001073 cb.onError(TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1074 new android.os.ParcelableException(ar.exception));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001075 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001076 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Nathan Harolde82c4b82018-12-18 19:40:37 -08001077 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001078 } else {
1079 // use the result as returned
1080 cb.onCellInfo((List<CellInfo>) ar.result);
1081 }
1082 } catch (RemoteException re) {
1083 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1084 }
1085 break;
1086 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001087 request = (MainThreadRequest) msg.obj;
1088 WorkSource ws = (WorkSource) request.argument;
1089 Phone phone = getPhoneFromRequest(request);
1090 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1091 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001092 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001093 ar = (AsyncResult) msg.obj;
1094 request = (MainThreadRequest) ar.userObj;
1095 if (ar.exception == null) {
1096 request.result = ar.result;
1097 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001098 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001099 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1100 ? new CdmaCellLocation() : new GsmCellLocation();
1101 }
1102
1103 synchronized (request) {
1104 request.notifyAll();
1105 }
1106 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001107 case CMD_MODEM_REBOOT:
1108 request = (MainThreadRequest) msg.obj;
1109 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001110 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001111 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001112 case EVENT_CMD_MODEM_REBOOT_DONE:
1113 handleNullReturnEvent(msg, "rebootModem");
1114 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001115 case CMD_REQUEST_ENABLE_MODEM:
1116 request = (MainThreadRequest) msg.obj;
1117 boolean enable = (boolean) request.argument;
1118 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001119 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001120 PhoneConfigurationManager.getInstance()
1121 .enablePhone(request.phone, enable, onCompleted);
1122 break;
1123 case EVENT_ENABLE_MODEM_DONE:
1124 ar = (AsyncResult) msg.obj;
1125 request = (MainThreadRequest) ar.userObj;
1126 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001127 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001128 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001129 if ((boolean) request.result) {
1130 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1131 updateModemStateMetrics();
1132 } else {
1133 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1134 + ar.exception);
1135 }
1136 notifyRequester(request);
1137 break;
1138 case CMD_GET_MODEM_STATUS:
1139 request = (MainThreadRequest) msg.obj;
1140 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1141 PhoneConfigurationManager.getInstance()
1142 .getPhoneStatusFromModem(request.phone, onCompleted);
1143 break;
1144 case EVENT_GET_MODEM_STATUS_DONE:
1145 ar = (AsyncResult) msg.obj;
1146 request = (MainThreadRequest) ar.userObj;
1147 int id = request.phone.getPhoneId();
1148 if (ar.exception == null && ar.result != null) {
1149 request.result = ar.result;
1150 //update the cache as modem status has changed
1151 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1152 (boolean) request.result);
1153 } else {
1154 // Return true if modem status cannot be retrieved. For most cases,
1155 // modem status is on. And for older version modems, GET_MODEM_STATUS
1156 // and disable modem are not supported. Modem is always on.
1157 // TODO: this should be fixed in R to support a third
1158 // status UNKNOWN b/131631629
1159 request.result = true;
1160 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1161 + ar.exception);
1162 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001163 notifyRequester(request);
1164 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001165 default:
1166 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1167 break;
1168 }
1169 }
Jake Hambye994d462014-02-03 13:10:13 -08001170
Pengquan Menga1bb6272018-09-06 09:59:22 -07001171 private void notifyRequester(MainThreadRequest request) {
1172 synchronized (request) {
1173 request.notifyAll();
1174 }
1175 }
1176
Jake Hambye994d462014-02-03 13:10:13 -08001177 private void handleNullReturnEvent(Message msg, String command) {
1178 AsyncResult ar = (AsyncResult) msg.obj;
1179 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1180 if (ar.exception == null) {
1181 request.result = true;
1182 } else {
1183 request.result = false;
1184 if (ar.exception instanceof CommandException) {
1185 loge(command + ": CommandException: " + ar.exception);
1186 } else {
1187 loge(command + ": Unknown exception");
1188 }
1189 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001190 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001191 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001192 }
1193
1194 /**
1195 * Posts the specified command to be executed on the main thread,
1196 * waits for the request to complete, and returns the result.
1197 * @see #sendRequestAsync
1198 */
1199 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001200 return sendRequest(
1201 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001202 }
1203
1204 /**
1205 * Posts the specified command to be executed on the main thread,
1206 * waits for the request to complete, and returns the result.
1207 * @see #sendRequestAsync
1208 */
1209 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1210 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001211 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001212 }
1213
1214 /**
1215 * Posts the specified command to be executed on the main thread,
1216 * waits for the request to complete, and returns the result.
1217 * @see #sendRequestAsync
1218 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001219 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001220 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001221 }
1222
1223 /**
1224 * Posts the specified command to be executed on the main thread,
1225 * waits for the request to complete, and returns the result.
1226 * @see #sendRequestAsync
1227 */
Nathan Harold92bed182018-10-12 18:16:49 -07001228 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1229 return sendRequest(command, argument, subId, null, workSource);
1230 }
1231
1232 /**
1233 * Posts the specified command to be executed on the main thread,
1234 * waits for the request to complete, and returns the result.
1235 * @see #sendRequestAsync
1236 */
1237 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1238 return sendRequest(
1239 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1240 }
1241
1242 /**
1243 * Posts the specified command to be executed on the main thread,
1244 * waits for the request to complete, and returns the result.
1245 * @see #sendRequestAsync
1246 */
1247 private Object sendRequest(
1248 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001249 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1250 throw new RuntimeException("This method will deadlock if called from the main thread.");
1251 }
1252
Nathan Harold92bed182018-10-12 18:16:49 -07001253 MainThreadRequest request = null;
1254 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1255 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1256 } else if (phone != null) {
1257 request = new MainThreadRequest(argument, phone, workSource);
1258 } else {
1259 request = new MainThreadRequest(argument, subId, workSource);
1260 }
1261
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001262 Message msg = mMainThreadHandler.obtainMessage(command, request);
1263 msg.sendToTarget();
1264
1265 // Wait for the request to complete
1266 synchronized (request) {
1267 while (request.result == null) {
1268 try {
1269 request.wait();
1270 } catch (InterruptedException e) {
1271 // Do nothing, go back and wait until the request is complete
1272 }
1273 }
1274 }
1275 return request.result;
1276 }
1277
1278 /**
1279 * Asynchronous ("fire and forget") version of sendRequest():
1280 * Posts the specified command to be executed on the main thread, and
1281 * returns immediately.
1282 * @see #sendRequest
1283 */
1284 private void sendRequestAsync(int command) {
1285 mMainThreadHandler.sendEmptyMessage(command);
1286 }
1287
1288 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001289 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001290 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001291 */
1292 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001293 sendRequestAsync(command, argument, null, null);
1294 }
1295
1296 /**
1297 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1298 * @see {@link #sendRequest(int,Object)}
1299 */
1300 private void sendRequestAsync(
1301 int command, Object argument, Phone phone, WorkSource workSource) {
1302 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001303 Message msg = mMainThreadHandler.obtainMessage(command, request);
1304 msg.sendToTarget();
1305 }
1306
1307 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001308 * Initialize the singleton PhoneInterfaceManager instance.
1309 * This is only done once, at startup, from PhoneApp.onCreate().
1310 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001311 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001312 synchronized (PhoneInterfaceManager.class) {
1313 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001314 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001315 } else {
1316 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1317 }
1318 return sInstance;
1319 }
1320 }
1321
1322 /** Private constructor; @see init() */
Jordan Liua39e6c12020-03-04 13:59:23 -08001323 @VisibleForTesting
1324 /* package */ PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001325 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001326 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001327 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001328 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1329 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001330 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001331 mTelephonySharedPreferences =
1332 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001333 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001334 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001335
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001336 publish();
1337 }
1338
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001339 private Phone getDefaultPhone() {
1340 Phone thePhone = getPhone(getDefaultSubscription());
1341 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1342 }
1343
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001344 private void publish() {
1345 if (DBG) log("publish: " + this);
1346
1347 ServiceManager.addService("phone", this);
1348 }
1349
Stuart Scott584921c2015-01-15 17:10:34 -08001350 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001351 if (request.phone != null) {
1352 return request.phone;
1353 } else {
1354 return getPhoneFromSubId(request.subId);
1355 }
1356 }
1357
1358 private Phone getPhoneFromSubId(int subId) {
1359 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1360 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001361 }
1362
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001363 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1364 Phone phone = getPhoneFromRequest(request);
1365 return phone == null ? null :
1366 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1367 }
1368
Wink Saville36469e72014-06-11 15:17:00 -07001369 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001370 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001371 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001372 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001373
1374 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001375 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001376 }
1377
Wink Savilleb564aae2014-10-23 10:18:09 -07001378 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001379 if (DBG) log("dial: " + number);
1380 // No permission check needed here: This is just a wrapper around the
1381 // ACTION_DIAL intent, which is available to any app since it puts up
1382 // the UI before it does anything.
1383
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001384 final long identity = Binder.clearCallingIdentity();
1385 try {
1386 String url = createTelUrl(number);
1387 if (url == null) {
1388 return;
1389 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001390
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001391 // PENDING: should we just silently fail if phone is offhook or ringing?
1392 PhoneConstants.State state = mCM.getState(subId);
1393 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1394 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1395 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1396 mApp.startActivity(intent);
1397 }
1398 } finally {
1399 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001400 }
1401 }
1402
1403 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001404 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001405 }
1406
Wink Savilleb564aae2014-10-23 10:18:09 -07001407 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001408 if (DBG) log("call: " + number);
1409
1410 // This is just a wrapper around the ACTION_CALL intent, but we still
1411 // need to do a permission check since we're calling startActivity()
1412 // from the context of the phone app.
1413 enforceCallPermission();
1414
1415 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1416 != AppOpsManager.MODE_ALLOWED) {
1417 return;
1418 }
1419
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001420 final long identity = Binder.clearCallingIdentity();
1421 try {
1422 String url = createTelUrl(number);
1423 if (url == null) {
1424 return;
1425 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001426
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001427 boolean isValid = false;
1428 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1429 if (slist != null) {
1430 for (SubscriptionInfo subInfoRecord : slist) {
1431 if (subInfoRecord.getSubscriptionId() == subId) {
1432 isValid = true;
1433 break;
1434 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001435 }
Wink Saville08874612014-08-31 19:19:58 -07001436 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001437 if (!isValid) {
1438 return;
1439 }
Wink Saville08874612014-08-31 19:19:58 -07001440
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001441 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1442 intent.putExtra(SUBSCRIPTION_KEY, subId);
1443 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1444 mApp.startActivity(intent);
1445 } finally {
1446 Binder.restoreCallingIdentity(identity);
1447 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001448 }
1449
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001450 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001451 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001452 }
1453
Wink Savilleb564aae2014-10-23 10:18:09 -07001454 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001455 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001456 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1457 }
1458
1459 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001460 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001461 }
1462
Wink Savilleb564aae2014-10-23 10:18:09 -07001463 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001464 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001465 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1466 }
1467
1468 /** {@hide} */
1469 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001470 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001471 }
1472
Wink Savilleb564aae2014-10-23 10:18:09 -07001473 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001474 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001475
1476 final long identity = Binder.clearCallingIdentity();
1477 try {
1478 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1479 checkSimPin.start();
1480 return checkSimPin.unlockSim(null, pin);
1481 } finally {
1482 Binder.restoreCallingIdentity(identity);
1483 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001484 }
1485
Wink Saville9de0f752013-10-22 19:04:03 -07001486 /** {@hide} */
1487 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001488 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001489 }
1490
Wink Savilleb564aae2014-10-23 10:18:09 -07001491 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001492 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001493
1494 final long identity = Binder.clearCallingIdentity();
1495 try {
1496 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1497 checkSimPuk.start();
1498 return checkSimPuk.unlockSim(puk, pin);
1499 } finally {
1500 Binder.restoreCallingIdentity(identity);
1501 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001502 }
1503
1504 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001505 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001506 * a synchronous one.
1507 */
1508 private static class UnlockSim extends Thread {
1509
1510 private final IccCard mSimCard;
1511
1512 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001513 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1514 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001515
1516 // For replies from SimCard interface
1517 private Handler mHandler;
1518
1519 // For async handler to identify request type
1520 private static final int SUPPLY_PIN_COMPLETE = 100;
1521
1522 public UnlockSim(IccCard simCard) {
1523 mSimCard = simCard;
1524 }
1525
1526 @Override
1527 public void run() {
1528 Looper.prepare();
1529 synchronized (UnlockSim.this) {
1530 mHandler = new Handler() {
1531 @Override
1532 public void handleMessage(Message msg) {
1533 AsyncResult ar = (AsyncResult) msg.obj;
1534 switch (msg.what) {
1535 case SUPPLY_PIN_COMPLETE:
1536 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1537 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001538 mRetryCount = msg.arg1;
1539 if (ar.exception != null) {
1540 if (ar.exception instanceof CommandException &&
1541 ((CommandException)(ar.exception)).getCommandError()
1542 == CommandException.Error.PASSWORD_INCORRECT) {
1543 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1544 } else {
1545 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1546 }
1547 } else {
1548 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1549 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001550 mDone = true;
1551 UnlockSim.this.notifyAll();
1552 }
1553 break;
1554 }
1555 }
1556 };
1557 UnlockSim.this.notifyAll();
1558 }
1559 Looper.loop();
1560 }
1561
1562 /*
1563 * Use PIN or PUK to unlock SIM card
1564 *
1565 * If PUK is null, unlock SIM card with PIN
1566 *
1567 * If PUK is not null, unlock SIM card with PUK and set PIN code
1568 */
Wink Saville9de0f752013-10-22 19:04:03 -07001569 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001570
1571 while (mHandler == null) {
1572 try {
1573 wait();
1574 } catch (InterruptedException e) {
1575 Thread.currentThread().interrupt();
1576 }
1577 }
1578 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1579
1580 if (puk == null) {
1581 mSimCard.supplyPin(pin, callback);
1582 } else {
1583 mSimCard.supplyPuk(puk, pin, callback);
1584 }
1585
1586 while (!mDone) {
1587 try {
1588 Log.d(LOG_TAG, "wait for done");
1589 wait();
1590 } catch (InterruptedException e) {
1591 // Restore the interrupted status
1592 Thread.currentThread().interrupt();
1593 }
1594 }
1595 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001596 int[] resultArray = new int[2];
1597 resultArray[0] = mResult;
1598 resultArray[1] = mRetryCount;
1599 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001600 }
1601 }
1602
1603 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001604 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001605
1606 }
1607
Wink Savilleb564aae2014-10-23 10:18:09 -07001608 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001609 // No permission check needed here: this call is harmless, and it's
1610 // needed for the ServiceState.requestStateUpdate() call (which is
1611 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001612 final long identity = Binder.clearCallingIdentity();
1613 try {
1614 final Phone phone = getPhone(subId);
1615 if (phone != null) {
1616 phone.updateServiceLocation();
1617 }
1618 } finally {
1619 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001620 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001621 }
1622
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001623 @Override
1624 public boolean isRadioOn(String callingPackage) {
1625 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001626 }
1627
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001628 @Override
1629 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001630 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001631 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001632 return false;
1633 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001634
1635 final long identity = Binder.clearCallingIdentity();
1636 try {
1637 return isRadioOnForSubscriber(subId);
1638 } finally {
1639 Binder.restoreCallingIdentity(identity);
1640 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001641 }
1642
1643 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001644 final long identity = Binder.clearCallingIdentity();
1645 try {
1646 final Phone phone = getPhone(subId);
1647 if (phone != null) {
1648 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1649 } else {
1650 return false;
1651 }
1652 } finally {
1653 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001654 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001655 }
1656
1657 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001658 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001659 }
Wink Saville36469e72014-06-11 15:17:00 -07001660
Wink Savilleb564aae2014-10-23 10:18:09 -07001661 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001662 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001663
1664 final long identity = Binder.clearCallingIdentity();
1665 try {
1666 final Phone phone = getPhone(subId);
1667 if (phone != null) {
1668 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1669 }
1670 } finally {
1671 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001672 }
Wink Saville36469e72014-06-11 15:17:00 -07001673 }
1674
1675 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001676 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001677 }
1678
Wink Savilleb564aae2014-10-23 10:18:09 -07001679 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001680 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001681
1682 final long identity = Binder.clearCallingIdentity();
1683 try {
1684 final Phone phone = getPhone(subId);
1685 if (phone == null) {
1686 return false;
1687 }
1688 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1689 toggleRadioOnOffForSubscriber(subId);
1690 }
1691 return true;
1692 } finally {
1693 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001694 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001695 }
Wink Saville36469e72014-06-11 15:17:00 -07001696
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001697 public boolean needMobileRadioShutdown() {
1698 /*
1699 * If any of the Radios are available, it will need to be
1700 * shutdown. So return true if any Radio is available.
1701 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001702 final long identity = Binder.clearCallingIdentity();
1703 try {
1704 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1705 Phone phone = PhoneFactory.getPhone(i);
1706 if (phone != null && phone.isRadioAvailable()) return true;
1707 }
1708 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1709 return false;
1710 } finally {
1711 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001712 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001713 }
1714
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001715 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001716 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001717 enforceModifyPermission();
1718
1719 final long identity = Binder.clearCallingIdentity();
1720 try {
1721 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1722 logv("Shutting down Phone " + i);
1723 shutdownRadioUsingPhoneId(i);
1724 }
1725 } finally {
1726 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001727 }
1728 }
1729
1730 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001731 Phone phone = PhoneFactory.getPhone(phoneId);
1732 if (phone != null && phone.isRadioAvailable()) {
1733 phone.shutdownRadio();
1734 }
1735 }
1736
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001737 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001738 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001739
1740 final long identity = Binder.clearCallingIdentity();
1741 try {
1742 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1743 if (defaultPhone != null) {
1744 defaultPhone.setRadioPower(turnOn);
1745 return true;
1746 } else {
1747 loge("There's no default phone.");
1748 return false;
1749 }
1750 } finally {
1751 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001752 }
Wink Saville36469e72014-06-11 15:17:00 -07001753 }
1754
Wink Savilleb564aae2014-10-23 10:18:09 -07001755 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001756 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001757
1758 final long identity = Binder.clearCallingIdentity();
1759 try {
1760 final Phone phone = getPhone(subId);
1761 if (phone != null) {
1762 phone.setRadioPower(turnOn);
1763 return true;
1764 } else {
1765 return false;
1766 }
1767 } finally {
1768 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001769 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001770 }
1771
Wink Saville36469e72014-06-11 15:17:00 -07001772 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001773 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001774 public boolean enableDataConnectivity() {
1775 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001776
1777 final long identity = Binder.clearCallingIdentity();
1778 try {
1779 int subId = mSubscriptionController.getDefaultDataSubId();
1780 final Phone phone = getPhone(subId);
1781 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001782 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001783 return true;
1784 } else {
1785 return false;
1786 }
1787 } finally {
1788 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001789 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001790 }
1791
Wink Saville36469e72014-06-11 15:17:00 -07001792 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001793 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001794 public boolean disableDataConnectivity() {
1795 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001796
1797 final long identity = Binder.clearCallingIdentity();
1798 try {
1799 int subId = mSubscriptionController.getDefaultDataSubId();
1800 final Phone phone = getPhone(subId);
1801 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001802 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001803 return true;
1804 } else {
1805 return false;
1806 }
1807 } finally {
1808 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001809 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001810 }
1811
Sanket Padawe356d7632015-06-22 14:03:32 -07001812 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001813 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001814 final long identity = Binder.clearCallingIdentity();
1815 try {
1816 final Phone phone = getPhone(subId);
1817 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001818 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001819 } else {
1820 return false;
1821 }
1822 } finally {
1823 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001824 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001825 }
1826
1827 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001828 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001829 }
1830
pkanwarae03a6b2016-11-06 20:37:09 -08001831 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001832 enforceCallPermission();
1833
1834 final long identity = Binder.clearCallingIdentity();
1835 try {
1836 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1837 return;
1838 }
1839 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1840 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1841 } finally {
1842 Binder.restoreCallingIdentity(identity);
1843 }
pkanwar32d516d2016-10-14 19:37:38 -07001844 };
1845
Wink Savilleb564aae2014-10-23 10:18:09 -07001846 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001847 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001848
1849 final long identity = Binder.clearCallingIdentity();
1850 try {
1851 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1852 return false;
1853 }
1854 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1855 } finally {
1856 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001857 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001858 }
1859
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001860 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001861 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001862 }
1863
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001864 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001865 final long identity = Binder.clearCallingIdentity();
1866 try {
1867 Phone phone = PhoneFactory.getPhone(slotIndex);
1868 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1869 PhoneConstantConversions.convertCallState(phone.getState());
1870 } finally {
1871 Binder.restoreCallingIdentity(identity);
1872 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001873 }
1874
Sanket Padawe356d7632015-06-22 14:03:32 -07001875 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001876 public int getDataState() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001877 final long identity = Binder.clearCallingIdentity();
1878 try {
1879 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1880 if (phone != null) {
1881 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1882 } else {
1883 return PhoneConstantConversions.convertDataState(
1884 PhoneConstants.DataState.DISCONNECTED);
1885 }
1886 } finally {
1887 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001888 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001889 }
1890
Sanket Padawe356d7632015-06-22 14:03:32 -07001891 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001892 public int getDataActivity() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001893 final long identity = Binder.clearCallingIdentity();
1894 try {
1895 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1896 if (phone != null) {
1897 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1898 } else {
1899 return TelephonyManager.DATA_ACTIVITY_NONE;
1900 }
1901 } finally {
1902 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001903 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001904 }
1905
1906 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001907 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001908 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001909 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08001910
1911 LocationAccessPolicy.LocationPermissionResult locationResult =
1912 LocationAccessPolicy.checkLocationPermission(mApp,
1913 new LocationAccessPolicy.LocationPermissionQuery.Builder()
1914 .setCallingPackage(callingPackage)
1915 .setCallingPid(Binder.getCallingPid())
1916 .setCallingUid(Binder.getCallingUid())
1917 .setMethod("getCellLocation")
Hall Liuc3f8eb62020-01-24 18:07:12 -08001918 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08001919 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
1920 .build());
1921 switch (locationResult) {
1922 case DENIED_HARD:
1923 throw new SecurityException("Not allowed to access cell location");
1924 case DENIED_SOFT:
1925 return new Bundle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001926 }
1927
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001928 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001929 final long identity = Binder.clearCallingIdentity();
1930 try {
1931 if (DBG_LOC) log("getCellLocation: is active user");
1932 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001933 int subId = mSubscriptionController.getDefaultDataSubId();
1934 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1935 cl.fillInNotifierBundle(data);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001936 return data;
1937 } finally {
1938 Binder.restoreCallingIdentity(identity);
1939 }
Svetoslav64fad262015-04-14 14:35:21 -07001940 }
1941
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001942 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001943 public String getNetworkCountryIsoForPhone(int phoneId) {
1944 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1945 // registered cell info, so return a NULL country instead.
1946 final long identity = Binder.clearCallingIdentity();
1947 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001948 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1949 // Get default phone in this case.
1950 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1951 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001952 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001953 // Todo: fix this when we can get the actual cellular network info when the device
1954 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001955 if (TelephonyManager.NETWORK_TYPE_IWLAN
1956 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1957 return "";
1958 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001959 Phone phone = PhoneFactory.getPhone(phoneId);
1960 if (phone != null) {
1961 ServiceStateTracker sst = phone.getServiceStateTracker();
1962 if (sst != null) {
1963 LocaleTracker lt = sst.getLocaleTracker();
1964 if (lt != null) {
1965 return lt.getCurrentCountry();
1966 }
1967 }
1968 }
1969 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001970 } finally {
1971 Binder.restoreCallingIdentity(identity);
1972 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001973 }
1974
1975 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001976 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001977 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001978 }
1979
Sanket Padawe356d7632015-06-22 14:03:32 -07001980 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001981 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001982 mApp.enforceCallingOrSelfPermission(
1983 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001984
1985 final long identity = Binder.clearCallingIdentity();
1986 try {
1987 final Phone phone = getPhone(subId);
1988 if (phone != null) {
1989 phone.enableLocationUpdates();
1990 }
1991 } finally {
1992 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001993 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001994 }
1995
1996 @Override
1997 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001998 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001999 }
2000
Sanket Padawe356d7632015-06-22 14:03:32 -07002001 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002002 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002003 mApp.enforceCallingOrSelfPermission(
2004 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002005
2006 final long identity = Binder.clearCallingIdentity();
2007 try {
2008 final Phone phone = getPhone(subId);
2009 if (phone != null) {
2010 phone.disableLocationUpdates();
2011 }
2012 } finally {
2013 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002014 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002015 }
2016
Nathan Harold31d7ff32018-10-15 20:20:30 -07002017 /**
2018 * Returns the target SDK version number for a given package name.
2019 *
2020 * @return target SDK if the package is found or INT_MAX.
2021 */
2022 private int getTargetSdk(String packageName) {
2023 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002024 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(
2025 packageName, 0);
Nathan Harold31d7ff32018-10-15 20:20:30 -07002026 if (ai != null) return ai.targetSdkVersion;
2027 } catch (PackageManager.NameNotFoundException unexpected) {
2028 }
2029 return Integer.MAX_VALUE;
2030 }
2031
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002032 @Override
2033 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07002034 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
2035 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002036 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2037 throw new SecurityException(
2038 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2039 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002040
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002041 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
2042 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2043 return null;
2044 }
Svetoslav64fad262015-04-14 14:35:21 -07002045
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002046 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002047
Nathan Haroldf180aac2018-06-01 18:43:55 -07002048 List<CellInfo> info = getAllCellInfo(callingPackage);
2049 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002050
Nathan Haroldf180aac2018-06-01 18:43:55 -07002051 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2052 for (CellInfo ci : info) {
2053 if (ci instanceof CellInfoGsm) {
2054 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2055 } else if (ci instanceof CellInfoWcdma) {
2056 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2057 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002058 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002059 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002060 }
2061
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002062 private List<CellInfo> getCachedCellInfo() {
2063 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2064 for (Phone phone : PhoneFactory.getPhones()) {
2065 List<CellInfo> info = phone.getAllCellInfo();
2066 if (info != null) cellInfos.addAll(info);
2067 }
2068 return cellInfos;
2069 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002070
2071 @Override
Svetoslav64fad262015-04-14 14:35:21 -07002072 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002073 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002074 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002075
2076 LocationAccessPolicy.LocationPermissionResult locationResult =
2077 LocationAccessPolicy.checkLocationPermission(mApp,
2078 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2079 .setCallingPackage(callingPackage)
2080 .setCallingPid(Binder.getCallingPid())
2081 .setCallingUid(Binder.getCallingUid())
2082 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002083 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002084 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2085 .build());
2086 switch (locationResult) {
2087 case DENIED_HARD:
2088 throw new SecurityException("Not allowed to access cell info");
2089 case DENIED_SOFT:
2090 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002091 }
2092
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002093 final int targetSdk = getTargetSdk(callingPackage);
2094 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2095 return getCachedCellInfo();
2096 }
2097
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002098 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002099 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002100 final long identity = Binder.clearCallingIdentity();
2101 try {
2102 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2103 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002104 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002105 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002106 if (info != null) cellInfos.addAll(info);
2107 }
2108 return cellInfos;
2109 } finally {
2110 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002111 }
2112 }
2113
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002114 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002115 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2116 requestCellInfoUpdateInternal(
2117 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2118 }
2119
2120 @Override
2121 public void requestCellInfoUpdateWithWorkSource(
2122 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2123 enforceModifyPermission();
2124 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2125 }
2126
2127 private void requestCellInfoUpdateInternal(
2128 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002129 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002130 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002131
2132 LocationAccessPolicy.LocationPermissionResult locationResult =
2133 LocationAccessPolicy.checkLocationPermission(mApp,
2134 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2135 .setCallingPackage(callingPackage)
2136 .setCallingPid(Binder.getCallingPid())
2137 .setCallingUid(Binder.getCallingUid())
2138 .setMethod("requestCellInfoUpdate")
2139 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2140 .build());
2141 switch (locationResult) {
2142 case DENIED_HARD:
2143 throw new SecurityException("Not allowed to access cell info");
2144 case DENIED_SOFT:
Nathan Haroldb3c5da42019-05-09 10:26:08 -07002145 try {
2146 cb.onCellInfo(new ArrayList<CellInfo>());
2147 } catch (RemoteException re) {
2148 // Drop without consequences
2149 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002150 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002151 }
2152
Nathan Harold32e84c42019-05-09 10:13:47 -07002153
2154 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002155 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2156
2157 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2158 }
2159
2160 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002161 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002162 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002163 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002164
2165 final long identity = Binder.clearCallingIdentity();
2166 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002167 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002168 } finally {
2169 Binder.restoreCallingIdentity(identity);
2170 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002171 }
2172
Shishir Agrawala9f32182016-04-12 12:00:16 -07002173 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002174 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002175 Phone phone = PhoneFactory.getPhone(slotIndex);
2176 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002177 return null;
2178 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002179 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002180 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2181 callingPackage, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002182 return null;
2183 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002184
2185 final long identity = Binder.clearCallingIdentity();
2186 try {
2187 return phone.getImei();
2188 } finally {
2189 Binder.restoreCallingIdentity(identity);
2190 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002191 }
2192
2193 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002194 public String getTypeAllocationCodeForSlot(int slotIndex) {
2195 Phone phone = PhoneFactory.getPhone(slotIndex);
2196 String tac = null;
2197 if (phone != null) {
2198 String imei = phone.getImei();
2199 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2200 }
2201 return tac;
2202 }
2203
2204 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002205 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002206 Phone phone = PhoneFactory.getPhone(slotIndex);
2207 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002208 return null;
2209 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002210
Jeff Davidson913390f2018-02-23 17:11:49 -08002211 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002212 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2213 callingPackage, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002214 return null;
2215 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002216
2217 final long identity = Binder.clearCallingIdentity();
2218 try {
2219 return phone.getMeid();
2220 } finally {
2221 Binder.restoreCallingIdentity(identity);
2222 }
Jack Yu2af8d712017-03-15 17:14:14 -07002223 }
2224
2225 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002226 public String getManufacturerCodeForSlot(int slotIndex) {
2227 Phone phone = PhoneFactory.getPhone(slotIndex);
2228 String manufacturerCode = null;
2229 if (phone != null) {
2230 String meid = phone.getMeid();
2231 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2232 }
2233 return manufacturerCode;
2234 }
2235
2236 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002237 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002238 Phone phone = PhoneFactory.getPhone(slotIndex);
2239 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002240 return null;
2241 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002242 int subId = phone.getSubId();
2243 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2244 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2245 return null;
2246 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002247
2248 final long identity = Binder.clearCallingIdentity();
2249 try {
2250 return phone.getDeviceSvn();
2251 } finally {
2252 Binder.restoreCallingIdentity(identity);
2253 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002254 }
2255
fionaxu43304da2017-11-27 22:51:16 -08002256 @Override
2257 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002258 final long identity = Binder.clearCallingIdentity();
2259 try {
2260 final Phone phone = getPhone(subId);
2261 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2262 } finally {
2263 Binder.restoreCallingIdentity(identity);
2264 }
fionaxu43304da2017-11-27 22:51:16 -08002265 }
2266
2267 @Override
2268 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002269 final long identity = Binder.clearCallingIdentity();
2270 try {
2271 final Phone phone = getPhone(subId);
2272 return phone == null ? null : phone.getCarrierName();
2273 } finally {
2274 Binder.restoreCallingIdentity(identity);
2275 }
fionaxu43304da2017-11-27 22:51:16 -08002276 }
2277
calvinpanffe225e2018-11-01 19:43:06 +08002278 @Override
chen xu0026ca62019-03-06 15:28:50 -08002279 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002280 final long identity = Binder.clearCallingIdentity();
2281 try {
2282 final Phone phone = getPhone(subId);
2283 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002284 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002285 } finally {
2286 Binder.restoreCallingIdentity(identity);
2287 }
2288 }
2289
2290 @Override
chen xu0026ca62019-03-06 15:28:50 -08002291 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002292 final long identity = Binder.clearCallingIdentity();
2293 try {
2294 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002295 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002296 } finally {
2297 Binder.restoreCallingIdentity(identity);
2298 }
2299 }
2300
chen xu651eec72018-11-11 19:03:44 -08002301 @Override
chen xu864e11c2018-12-06 22:10:03 -08002302 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2303 if (!isSubscriptionMccMnc) {
2304 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2305 }
chen xu651eec72018-11-11 19:03:44 -08002306 final Phone phone = PhoneFactory.getPhone(slotIndex);
2307 if (phone == null) {
2308 return TelephonyManager.UNKNOWN_CARRIER_ID;
2309 }
2310 final long identity = Binder.clearCallingIdentity();
2311 try {
2312 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2313 } finally {
2314 Binder.restoreCallingIdentity(identity);
2315 }
2316 }
2317
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002318 //
2319 // Internal helper methods.
2320 //
2321
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002322 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002323 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2324 *
2325 * @throws SecurityException if the caller does not have the required permission
2326 */
2327 private void enforceModifyPermission() {
2328 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2329 }
2330
2331 /**
2332 * Make sure the caller has the CALL_PHONE permission.
2333 *
2334 * @throws SecurityException if the caller does not have the required permission
2335 */
2336 private void enforceCallPermission() {
2337 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2338 }
2339
Stuart Scott8eef64f2015-04-08 15:13:54 -07002340 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002341 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002342 "ConnectivityService");
2343 }
2344
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002345 private String createTelUrl(String number) {
2346 if (TextUtils.isEmpty(number)) {
2347 return null;
2348 }
2349
Jake Hambye994d462014-02-03 13:10:13 -08002350 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002351 }
2352
Ihab Awadf9e92732013-12-05 18:02:52 -08002353 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002354 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2355 }
2356
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002357 private static void logv(String msg) {
2358 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2359 }
2360
Ihab Awadf9e92732013-12-05 18:02:52 -08002361 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002362 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2363 }
2364
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002365 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002366 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002367 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002368 }
2369
Sanket Padawe356d7632015-06-22 14:03:32 -07002370 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002371 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002372 final long identity = Binder.clearCallingIdentity();
2373 try {
2374 final Phone phone = PhoneFactory.getPhone(slotIndex);
2375 if (phone == null) {
2376 return PhoneConstants.PHONE_TYPE_NONE;
2377 } else {
2378 return phone.getPhoneType();
2379 }
2380 } finally {
2381 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002382 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002383 }
2384
2385 /**
2386 * Returns the CDMA ERI icon index to display
2387 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002388 @Override
2389 public int getCdmaEriIconIndex(String callingPackage) {
2390 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002391 }
2392
Sanket Padawe356d7632015-06-22 14:03:32 -07002393 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002394 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002395 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002396 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002397 return -1;
2398 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002399
2400 final long identity = Binder.clearCallingIdentity();
2401 try {
2402 final Phone phone = getPhone(subId);
2403 if (phone != null) {
2404 return phone.getCdmaEriIconIndex();
2405 } else {
2406 return -1;
2407 }
2408 } finally {
2409 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002410 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002411 }
2412
2413 /**
2414 * Returns the CDMA ERI icon mode,
2415 * 0 - ON
2416 * 1 - FLASHING
2417 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002418 @Override
2419 public int getCdmaEriIconMode(String callingPackage) {
2420 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002421 }
2422
Sanket Padawe356d7632015-06-22 14:03:32 -07002423 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002424 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002425 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002426 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002427 return -1;
2428 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002429
2430 final long identity = Binder.clearCallingIdentity();
2431 try {
2432 final Phone phone = getPhone(subId);
2433 if (phone != null) {
2434 return phone.getCdmaEriIconMode();
2435 } else {
2436 return -1;
2437 }
2438 } finally {
2439 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002440 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002441 }
2442
2443 /**
2444 * Returns the CDMA ERI text,
2445 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002446 @Override
2447 public String getCdmaEriText(String callingPackage) {
2448 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002449 }
2450
Sanket Padawe356d7632015-06-22 14:03:32 -07002451 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002452 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002453 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002454 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002455 return null;
2456 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002457
2458 final long identity = Binder.clearCallingIdentity();
2459 try {
2460 final Phone phone = getPhone(subId);
2461 if (phone != null) {
2462 return phone.getCdmaEriText();
2463 } else {
2464 return null;
2465 }
2466 } finally {
2467 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002468 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002469 }
2470
2471 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002472 * Returns the CDMA MDN.
2473 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002474 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002475 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002476 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2477 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002478
2479 final long identity = Binder.clearCallingIdentity();
2480 try {
2481 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002482 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002483 return phone.getLine1Number();
2484 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002485 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002486 return null;
2487 }
2488 } finally {
2489 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002490 }
2491 }
2492
2493 /**
2494 * Returns the CDMA MIN.
2495 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002496 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002497 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002498 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2499 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002500
2501 final long identity = Binder.clearCallingIdentity();
2502 try {
2503 final Phone phone = getPhone(subId);
2504 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2505 return phone.getCdmaMin();
2506 } else {
2507 return null;
2508 }
2509 } finally {
2510 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002511 }
2512 }
2513
Hall Liud892bec2018-11-30 14:51:45 -08002514 @Override
2515 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2516 INumberVerificationCallback callback, String callingPackage) {
2517 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2518 != PERMISSION_GRANTED) {
2519 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2520 }
2521 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2522
2523 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2524 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2525 throw new SecurityException("Calling package must be configured in the device config");
2526 }
2527
2528 if (range == null) {
2529 throw new NullPointerException("Range must be non-null");
2530 }
2531
2532 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002533 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002534
2535 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2536 }
2537
Junda Liuca05d5d2014-08-14 22:36:34 -07002538 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002539 * Returns true if CDMA provisioning needs to run.
2540 */
2541 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002542 final long identity = Binder.clearCallingIdentity();
2543 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002544 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002545 } finally {
2546 Binder.restoreCallingIdentity(identity);
2547 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002548 }
2549
2550 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002551 * Sets the voice mail number of a given subId.
2552 */
2553 @Override
2554 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002555 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002556
2557 final long identity = Binder.clearCallingIdentity();
2558 try {
2559 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2560 new Pair<String, String>(alphaTag, number), new Integer(subId));
2561 return success;
2562 } finally {
2563 Binder.restoreCallingIdentity(identity);
2564 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002565 }
2566
Ta-wei Yen87c49842016-05-13 21:19:52 -07002567 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002568 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2569 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002570 String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002571 if (!TextUtils.equals(callingPackage, systemDialer)) {
2572 throw new SecurityException("caller must be system dialer");
2573 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002574
2575 final long identity = Binder.clearCallingIdentity();
2576 try {
2577 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2578 if (phoneAccountHandle == null) {
2579 return null;
2580 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002581 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002582 } finally {
2583 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002584 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002585 }
2586
2587 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002588 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002589 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002590 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002591 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002592 return null;
2593 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002594
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002595 final long identity = Binder.clearCallingIdentity();
2596 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002597 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002598 } finally {
2599 Binder.restoreCallingIdentity(identity);
2600 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002601 }
2602
2603 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002604 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2605 VisualVoicemailSmsFilterSettings settings) {
2606 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002607
2608 final long identity = Binder.clearCallingIdentity();
2609 try {
2610 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002611 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002612 } finally {
2613 Binder.restoreCallingIdentity(identity);
2614 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002615 }
2616
2617 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002618 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2619 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002620
2621 final long identity = Binder.clearCallingIdentity();
2622 try {
2623 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002624 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002625 } finally {
2626 Binder.restoreCallingIdentity(identity);
2627 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002628 }
2629
2630 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002631 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2632 String callingPackage, int subId) {
2633 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002634
2635 final long identity = Binder.clearCallingIdentity();
2636 try {
2637 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002638 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002639 } finally {
2640 Binder.restoreCallingIdentity(identity);
2641 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002642 }
2643
2644 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002645 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002646 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002647
2648 final long identity = Binder.clearCallingIdentity();
2649 try {
2650 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002651 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002652 } finally {
2653 Binder.restoreCallingIdentity(identity);
2654 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002655 }
2656
2657 @Override
2658 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2659 String number, int port, String text, PendingIntent sentIntent) {
2660 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002661 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002662 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07002663 SmsController smsController = PhoneFactory.getSmsController();
2664 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
2665 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002666 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07002667
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002668 /**
fionaxu0152e512016-11-14 13:36:14 -08002669 * Sets the voice activation state of a given subId.
2670 */
2671 @Override
2672 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002673 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2674 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002675
2676 final long identity = Binder.clearCallingIdentity();
2677 try {
2678 final Phone phone = getPhone(subId);
2679 if (phone != null) {
2680 phone.setVoiceActivationState(activationState);
2681 } else {
2682 loge("setVoiceActivationState fails with invalid subId: " + subId);
2683 }
2684 } finally {
2685 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002686 }
2687 }
2688
2689 /**
2690 * Sets the data activation state of a given subId.
2691 */
2692 @Override
2693 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002694 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2695 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002696
2697 final long identity = Binder.clearCallingIdentity();
2698 try {
2699 final Phone phone = getPhone(subId);
2700 if (phone != null) {
2701 phone.setDataActivationState(activationState);
2702 } else {
2703 loge("setVoiceActivationState fails with invalid subId: " + subId);
2704 }
2705 } finally {
2706 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002707 }
2708 }
2709
2710 /**
2711 * Returns the voice activation state of a given subId.
2712 */
2713 @Override
2714 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002715 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002716
fionaxu0152e512016-11-14 13:36:14 -08002717 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002718 final long identity = Binder.clearCallingIdentity();
2719 try {
2720 if (phone != null) {
2721 return phone.getVoiceActivationState();
2722 } else {
2723 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2724 }
2725 } finally {
2726 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002727 }
2728 }
2729
2730 /**
2731 * Returns the data activation state of a given subId.
2732 */
2733 @Override
2734 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002735 enforceReadPrivilegedPermission("getDataActivationState");
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.getDataActivationState();
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 /**
Wink Saville36469e72014-06-11 15:17:00 -07002751 * Returns the unread count of voicemails for a subId
2752 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002753 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002754 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2755 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2756 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2757 return 0;
2758 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002759 final long identity = Binder.clearCallingIdentity();
2760 try {
2761 final Phone phone = getPhone(subId);
2762 if (phone != null) {
2763 return phone.getVoiceMessageCount();
2764 } else {
2765 return 0;
2766 }
2767 } finally {
2768 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002769 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002770 }
2771
2772 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002773 * returns true, if the device is in a state where both voice and data
2774 * are supported simultaneously. This can change based on location or network condition.
2775 */
2776 @Override
2777 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002778 final long identity = Binder.clearCallingIdentity();
2779 try {
2780 final Phone phone = getPhone(subId);
2781 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2782 } finally {
2783 Binder.restoreCallingIdentity(identity);
2784 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002785 }
2786
2787 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002788 * Send the dialer code if called from the current default dialer or the caller has
2789 * carrier privilege.
2790 * @param inputCode The dialer code to send
2791 */
2792 @Override
2793 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002794 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002795 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002796 String defaultDialer = TelecomManager.from(defaultPhone.getContext())
2797 .getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002798 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002799 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2800 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002801 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002802
2803 final long identity = Binder.clearCallingIdentity();
2804 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002805 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002806 } finally {
2807 Binder.restoreCallingIdentity(identity);
2808 }
fionaxu235cc5e2017-03-06 22:25:57 -08002809 }
2810
Pengquan Menga1bb6272018-09-06 09:59:22 -07002811 @Override
2812 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002813 if (!isActiveSubscription(subId)) {
2814 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2815 }
2816
Pengquan Menga1bb6272018-09-06 09:59:22 -07002817 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2818 }
2819
Brad Ebinger35c841c2018-10-01 10:40:55 -07002820 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002821 public boolean isInEmergencySmsMode() {
2822 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2823 final long identity = Binder.clearCallingIdentity();
2824 try {
2825 for (Phone phone : PhoneFactory.getPhones()) {
2826 if (phone.isInEmergencySmsMode()) {
2827 return true;
2828 }
2829 }
2830 } finally {
2831 Binder.restoreCallingIdentity(identity);
2832 }
2833 return false;
2834 }
2835
2836 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002837 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2838 throws RemoteException {
2839 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002840 final long token = Binder.clearCallingIdentity();
2841 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002842 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002843 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002844 .addRegistrationCallbackForSubscription(c, subId);
2845 } finally {
2846 Binder.restoreCallingIdentity(token);
2847 }
2848 }
2849
2850 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002851 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2852 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002853 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2854 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2855 }
2856 Binder.withCleanCallingIdentity(() -> {
2857 try {
2858 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002859 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002860 .removeRegistrationCallbackForSubscription(c, subId);
2861 } catch (IllegalArgumentException e) {
2862 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2863 + "is inactive, ignoring unregister.");
2864 // If the subscription is no longer active, just return, since the callback
2865 // will already have been removed internally.
2866 }
2867 });
Brad Ebinger35c841c2018-10-01 10:40:55 -07002868 }
2869
2870 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002871 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2872 throws RemoteException {
2873 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002874 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2875 final long token = Binder.clearCallingIdentity();
2876 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002877 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002878 .addCapabilitiesCallbackForSubscription(c, subId);
2879 } finally {
2880 Binder.restoreCallingIdentity(token);
2881 }
2882 }
2883
2884 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002885 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2886 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002887
2888 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2889 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2890 }
2891 Binder.withCleanCallingIdentity(() -> {
2892 try {
2893 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002894 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002895 .removeCapabilitiesCallbackForSubscription(c, subId);
2896 } catch (IllegalArgumentException e) {
2897 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
2898 + "is inactive, ignoring unregister.");
2899 // If the subscription is no longer active, just return, since the callback
2900 // will already have been removed internally.
2901 }
2902 });
Brad Ebinger35c841c2018-10-01 10:40:55 -07002903 }
2904
2905 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002906 public boolean isCapable(int subId, int capability, int regTech) {
2907 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002908 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2909 final long token = Binder.clearCallingIdentity();
2910 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002911 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002912 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2913 } catch (ImsException e) {
2914 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2915 return false;
Brad Ebinger6b5ac222019-02-04 14:36:52 -08002916 } catch (IllegalArgumentException e) {
2917 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
2918 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07002919 } finally {
2920 Binder.restoreCallingIdentity(token);
2921 }
2922 }
2923
2924 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002925 public boolean isAvailable(int subId, int capability, int regTech) {
2926 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002927 final long token = Binder.clearCallingIdentity();
2928 try {
2929 Phone phone = getPhone(subId);
2930 if (phone == null) return false;
2931 return phone.isImsCapabilityAvailable(capability, regTech);
2932 } finally {
2933 Binder.restoreCallingIdentity(token);
2934 }
2935 }
2936
2937 @Override
2938 public boolean isAdvancedCallingSettingEnabled(int subId) {
2939 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2940 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2941 final long token = Binder.clearCallingIdentity();
2942 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002943 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002944 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2945 } finally {
2946 Binder.restoreCallingIdentity(token);
2947 }
2948 }
2949
2950 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08002951 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002952 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08002953 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002954 final long identity = Binder.clearCallingIdentity();
2955 try {
2956 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002957 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002958 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2959 } finally {
2960 Binder.restoreCallingIdentity(identity);
2961 }
2962 }
2963
2964 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002965 public boolean isVtSettingEnabled(int subId) {
2966 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002967 final long identity = Binder.clearCallingIdentity();
2968 try {
2969 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002970 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002971 getSlotIndexOrException(subId)).isVtEnabledByUser();
2972 } finally {
2973 Binder.restoreCallingIdentity(identity);
2974 }
2975 }
2976
2977 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08002978 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002979 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08002980 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002981 final long identity = Binder.clearCallingIdentity();
2982 try {
2983 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002984 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger35c841c2018-10-01 10:40:55 -07002985 } finally {
2986 Binder.restoreCallingIdentity(identity);
2987 }
2988 }
2989
2990 @Override
2991 public boolean isVoWiFiSettingEnabled(int subId) {
2992 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
2993 final long identity = Binder.clearCallingIdentity();
2994 try {
2995 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002996 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002997 getSlotIndexOrException(subId)).isWfcEnabledByUser();
2998 } finally {
2999 Binder.restoreCallingIdentity(identity);
3000 }
3001 }
3002
3003 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003004 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003005 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003006 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003007 final long identity = Binder.clearCallingIdentity();
3008 try {
3009 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003010 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003011 } finally {
3012 Binder.restoreCallingIdentity(identity);
3013 }
3014 }
3015
3016 @Override
3017 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3018 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3019 final long identity = Binder.clearCallingIdentity();
3020 try {
3021 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003022 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003023 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
3024 } finally {
3025 Binder.restoreCallingIdentity(identity);
3026 }
3027 }
3028
3029 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003030 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003031 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003032 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003033 final long identity = Binder.clearCallingIdentity();
3034 try {
3035 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003036 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003037 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
3038 } finally {
3039 Binder.restoreCallingIdentity(identity);
3040 }
3041 }
3042
3043 @Override
3044 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3045 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3046 "setVoWiFiNonPersistent");
3047 final long identity = Binder.clearCallingIdentity();
3048 try {
3049 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003050 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003051 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003052 } finally {
3053 Binder.restoreCallingIdentity(identity);
3054 }
3055 }
3056
3057 @Override
3058 public int getVoWiFiModeSetting(int subId) {
3059 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3060 final long identity = Binder.clearCallingIdentity();
3061 try {
3062 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003063 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003064 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
3065 } finally {
3066 Binder.restoreCallingIdentity(identity);
3067 }
3068 }
3069
3070 @Override
3071 public void setVoWiFiModeSetting(int subId, int mode) {
3072 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3073 "setVoWiFiModeSetting");
3074 final long identity = Binder.clearCallingIdentity();
3075 try {
3076 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003077 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003078 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
3079 } finally {
3080 Binder.restoreCallingIdentity(identity);
3081 }
3082 }
3083
3084 @Override
3085 public int getVoWiFiRoamingModeSetting(int subId) {
3086 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3087 final long identity = Binder.clearCallingIdentity();
3088 try {
3089 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003090 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003091 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
3092 } finally {
3093 Binder.restoreCallingIdentity(identity);
3094 }
3095 }
3096
3097 @Override
3098 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3099 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3100 "setVoWiFiRoamingModeSetting");
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 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003105 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
3106 } finally {
3107 Binder.restoreCallingIdentity(identity);
3108 }
3109 }
3110
3111 @Override
3112 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3113 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3114 "setRttCapabilityEnabled");
3115 final long identity = Binder.clearCallingIdentity();
3116 try {
3117 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003118 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003119 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3120 } finally {
3121 Binder.restoreCallingIdentity(identity);
3122 }
3123 }
3124
3125 @Override
3126 public boolean isTtyOverVolteEnabled(int subId) {
3127 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3128 final long identity = Binder.clearCallingIdentity();
3129 try {
3130 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003131 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003132 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
3133 } finally {
3134 Binder.restoreCallingIdentity(identity);
3135 }
3136 }
3137
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003138 @Override
3139 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3140 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3141 final long identity = Binder.clearCallingIdentity();
3142 try {
3143 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003144 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003145 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003146 } finally {
3147 Binder.restoreCallingIdentity(identity);
3148 }
3149 }
3150
3151 @Override
3152 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3153 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3154 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003155 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3156 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3157 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003158 try {
3159 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003160 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003161 .removeProvisioningCallbackForSubscription(callback, subId);
3162 } catch (IllegalArgumentException e) {
3163 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3164 + "is inactive, ignoring unregister.");
3165 // If the subscription is no longer active, just return, since the callback will already
3166 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003167 } finally {
3168 Binder.restoreCallingIdentity(identity);
3169 }
3170 }
3171
3172 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003173 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3174 boolean isProvisioned) {
3175 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3176 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3177 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3178 }
3179 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3180 "setProvisioningStatusForCapability");
3181 final long identity = Binder.clearCallingIdentity();
3182 try {
3183 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3184 Phone phone = getPhone(subId);
3185 if (phone == null) {
3186 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3187 + subId);
3188 return;
3189 }
3190 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3191 return;
3192 }
3193
3194 // this capability requires provisioning, route to the correct API.
3195 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3196 switch (capability) {
3197 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3198 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3199 ims.setVolteProvisioned(isProvisioned);
3200 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3201 ims.setWfcProvisioned(isProvisioned);
3202 }
3203 break;
3204 }
3205 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3206 // There is currently no difference in VT provisioning type.
3207 ims.setVtProvisioned(isProvisioned);
3208 break;
3209 }
3210 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3211 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3212 // change the capability of the feature instead if needed.
3213 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3214 == isProvisioned) {
3215 // No change in provisioning.
3216 return;
3217 }
3218 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3219 try {
3220 ims.changeMmTelCapability(capability, tech, isProvisioned);
3221 } catch (ImsException e) {
3222 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3223 + ", Exception" + e.getMessage());
3224 }
3225 break;
3226 }
3227 default: {
3228 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3229 + capability + "', which does not require provisioning.");
3230 }
3231 }
3232
3233 } finally {
3234 Binder.restoreCallingIdentity(identity);
3235 }
3236 }
3237
3238 @Override
3239 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3240 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3241 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3242 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3243 }
3244 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3245 final long identity = Binder.clearCallingIdentity();
3246 try {
3247 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3248 Phone phone = getPhone(subId);
3249 if (phone == null) {
3250 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3251 + subId);
3252 // We will fail with "true" as the provisioning status because this is the default
3253 // if we do not require provisioning.
3254 return true;
3255 }
3256
3257 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3258 return true;
3259 }
3260
3261 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3262 switch (capability) {
3263 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3264 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3265 return ims.isVolteProvisionedOnDevice();
3266 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3267 return ims.isWfcProvisionedOnDevice();
3268 }
3269 // This should never happen, since we are checking tech above to make sure it
3270 // is either LTE or IWLAN.
3271 throw new IllegalArgumentException("Invalid radio technology for voice "
3272 + "capability.");
3273 }
3274 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3275 // There is currently no difference in VT provisioning type.
3276 return ims.isVtProvisionedOnDevice();
3277 }
3278 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3279 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3280 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3281 }
3282 default: {
3283 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3284 + capability + "', which does not require provisioning.");
3285 }
3286 }
3287
3288 } finally {
3289 Binder.restoreCallingIdentity(identity);
3290 }
3291 }
3292
3293 @Override
3294 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3295 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3296 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3297 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3298 }
3299 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3300 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3301 return (provisionedBits & capability) > 0;
3302 }
3303
3304 @Override
3305 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3306 boolean isProvisioned) {
3307 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3308 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3309 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3310 }
3311 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3312 "setProvisioningStatusForCapability");
3313 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3314 // If the current provisioning status for capability already matches isProvisioned,
3315 // do nothing.
3316 if (((provisionedBits & capability) > 0) == isProvisioned) {
3317 return;
3318 }
3319 if (isProvisioned) {
3320 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3321 } else {
3322 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3323 }
3324 }
3325
3326 /**
3327 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3328 * technology. The bitfield should mirror the bitfield defined by
3329 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3330 */
3331 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3332 String key = getMmTelProvisioningKey(subId, tech);
3333 // Default is no capabilities are provisioned.
3334 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3335 }
3336
3337 /**
3338 * Sets the MmTel capability provisioning bitfield (defined by
3339 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3340 * technology specified.
3341 *
3342 * Note: This is a synchronous command and should not be called on UI thread.
3343 */
3344 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3345 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3346 String key = getMmTelProvisioningKey(subId, tech);
3347 editor.putInt(key, newField);
3348 editor.commit();
3349 }
3350
3351 private static String getMmTelProvisioningKey(int subId, int tech) {
3352 // resulting key is provision_ims_mmtel_{subId}_{tech}
3353 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3354 }
3355
3356 /**
3357 * Query CarrierConfig to see if the specified capability requires provisioning for the
3358 * carrier associated with the subscription id.
3359 */
3360 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3361 int capability) {
3362 CarrierConfigManager configManager = new CarrierConfigManager(context);
3363 PersistableBundle c = configManager.getConfigForSubId(subId);
3364 boolean requireUtProvisioning = c.getBoolean(
3365 // By default, this config is true (even if there is no SIM). We also check to make
3366 // sure the subscription needs provisioning here, so we do not need to check for
3367 // the no-SIM case, where we would normally shortcut this to false.
3368 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, true)
3369 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3370 false);
3371 boolean requireVoiceVtProvisioning = c.getBoolean(
3372 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3373
3374 // First check to make sure that the capability requires provisioning.
3375 switch (capability) {
3376 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3377 // intentional fallthrough
3378 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3379 if (requireVoiceVtProvisioning) {
3380 // Voice and Video requires provisioning
3381 return true;
3382 }
3383 break;
3384 }
3385 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3386 if (requireUtProvisioning) {
3387 // UT requires provisioning
3388 return true;
3389 }
3390 break;
3391 }
3392 }
3393 return false;
3394 }
3395
3396 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003397 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003398 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3399 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3400 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003401 enforceReadPrivilegedPermission("getImsProvisioningInt");
3402 final long identity = Binder.clearCallingIdentity();
3403 try {
3404 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003405 int slotId = getSlotIndex(subId);
3406 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3407 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3408 + subId + "' for key:" + key);
3409 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3410 }
3411 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003412 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003413 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3414 + subId + "' for key:" + key);
3415 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003416 } finally {
3417 Binder.restoreCallingIdentity(identity);
3418 }
3419 }
3420
3421 @Override
3422 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003423 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3424 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3425 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003426 enforceReadPrivilegedPermission("getImsProvisioningString");
3427 final long identity = Binder.clearCallingIdentity();
3428 try {
3429 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003430 int slotId = getSlotIndex(subId);
3431 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3432 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3433 + subId + "' for key:" + key);
3434 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3435 }
3436 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003437 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003438 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3439 + subId + "' for key:" + key);
3440 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003441 } finally {
3442 Binder.restoreCallingIdentity(identity);
3443 }
3444 }
3445
3446 @Override
3447 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003448 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3449 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3450 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003451 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3452 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003453 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, "setImsProvisioningInt: called with an inactive subscription id '"
3459 + subId + "' for key:" + key);
3460 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3461 }
3462 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003463 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003464 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3465 + "' for key:" + key);
3466 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003467 } finally {
3468 Binder.restoreCallingIdentity(identity);
3469 }
3470 }
3471
3472 @Override
3473 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003474 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3475 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3476 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003477 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3478 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003479 final long identity = Binder.clearCallingIdentity();
3480 try {
3481 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003482 int slotId = getSlotIndex(subId);
3483 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3484 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3485 + subId + "' for key:" + key);
3486 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3487 }
3488 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003489 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003490 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3491 + "' for key:" + key);
3492 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003493 } finally {
3494 Binder.restoreCallingIdentity(identity);
3495 }
3496 }
3497
Brad Ebinger35c841c2018-10-01 10:40:55 -07003498 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
3499 int slotId = SubscriptionManager.getSlotIndex(subId);
3500 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003501 throw new IllegalArgumentException("Invalid Subscription Id, subId=" + subId);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003502 }
3503 return slotId;
3504 }
3505
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003506 private int getSlotIndex(int subId) {
3507 int slotId = SubscriptionManager.getSlotIndex(subId);
3508 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3509 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3510 }
3511 return slotId;
3512 }
3513
Wink Saville36469e72014-06-11 15:17:00 -07003514 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07003515 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07003516 */
3517 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003518 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Nathan Harold9042f0b2019-05-21 15:51:27 -07003519 if (getTargetSdk(callingPackage) >= android.os.Build.VERSION_CODES.Q
3520 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
3521 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003522 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3523 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003524
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003525 final long identity = Binder.clearCallingIdentity();
3526 try {
3527 final Phone phone = getPhone(subId);
3528 if (phone != null) {
3529 return phone.getServiceState().getDataNetworkType();
3530 } else {
3531 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3532 }
3533 } finally {
3534 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003535 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003536 }
3537
3538 /**
3539 * Returns the data network type
3540 */
3541 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003542 public int getDataNetworkType(String callingPackage) {
3543 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003544 }
3545
3546 /**
3547 * Returns the data network type for a subId
3548 */
3549 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003550 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003551 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003552 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003553 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3554 }
3555
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003556 final long identity = Binder.clearCallingIdentity();
3557 try {
3558 final Phone phone = getPhone(subId);
3559 if (phone != null) {
3560 return phone.getServiceState().getDataNetworkType();
3561 } else {
3562 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3563 }
3564 } finally {
3565 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003566 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003567 }
3568
3569 /**
Wink Saville36469e72014-06-11 15:17:00 -07003570 * Returns the Voice network type for a subId
3571 */
3572 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003573 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003574 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003575 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003576 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3577 }
3578
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003579 final long identity = Binder.clearCallingIdentity();
3580 try {
3581 final Phone phone = getPhone(subId);
3582 if (phone != null) {
3583 return phone.getServiceState().getVoiceNetworkType();
3584 } else {
3585 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3586 }
3587 } finally {
3588 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003589 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003590 }
3591
3592 /**
3593 * @return true if a ICC card is present
3594 */
3595 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003596 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003597 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3598 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003599 }
3600
3601 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003602 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003603 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003604 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003605 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003606 final long identity = Binder.clearCallingIdentity();
3607 try {
3608 final Phone phone = PhoneFactory.getPhone(slotIndex);
3609 if (phone != null) {
3610 return phone.getIccCard().hasIccCard();
3611 } else {
3612 return false;
3613 }
3614 } finally {
3615 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003616 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003617 }
3618
3619 /**
3620 * Return if the current radio is LTE on CDMA. This
3621 * is a tri-state return value as for a period of time
3622 * the mode may be unknown.
3623 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003624 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003625 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003626 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003627 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003628 @Override
3629 public int getLteOnCdmaMode(String callingPackage) {
3630 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003631 }
3632
Sanket Padawe356d7632015-06-22 14:03:32 -07003633 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003634 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003635 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003636 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003637 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3638 }
3639
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003640 final long identity = Binder.clearCallingIdentity();
3641 try {
3642 final Phone phone = getPhone(subId);
3643 if (phone == null) {
3644 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3645 } else {
3646 return phone.getLteOnCdmaMode();
3647 }
3648 } finally {
3649 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003650 }
Wink Saville36469e72014-06-11 15:17:00 -07003651 }
3652
Wink Saville36469e72014-06-11 15:17:00 -07003653 /**
3654 * {@hide}
3655 * Returns Default subId, 0 in the case of single standby.
3656 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003657 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003658 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003659 }
3660
Shishir Agrawala9f32182016-04-12 12:00:16 -07003661 private int getSlotForDefaultSubscription() {
3662 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3663 }
3664
Wink Savilleb564aae2014-10-23 10:18:09 -07003665 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003666 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003667 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003668
Pengquan Menge92a50d2018-09-21 15:54:48 -07003669 private boolean isActiveSubscription(int subId) {
3670 return mSubscriptionController.isActiveSubId(subId);
3671 }
3672
Ihab Awadf2177b72013-11-25 13:33:23 -08003673 /**
3674 * @see android.telephony.TelephonyManager.WifiCallingChoices
3675 */
3676 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003677 final long identity = Binder.clearCallingIdentity();
3678 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003679 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003680 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3681 getWhenToMakeWifiCallsDefaultPreference());
3682 } finally {
3683 Binder.restoreCallingIdentity(identity);
3684 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003685 }
3686
3687 /**
3688 * @see android.telephony.TelephonyManager.WifiCallingChoices
3689 */
3690 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003691 final long identity = Binder.clearCallingIdentity();
3692 try {
3693 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003694 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003695 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3696 } finally {
3697 Binder.restoreCallingIdentity(identity);
3698 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003699 }
3700
Sailesh Nepald1e68152013-12-12 19:08:02 -08003701 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003702 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003703 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003704 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003705
Jordan Liu4c733742019-02-28 12:03:40 -08003706 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
3707 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
3708 if (phoneId == -1) {
3709 throw new IllegalArgumentException("Given slot index: " + slotIndex
3710 + " does not correspond to an active phone");
3711 }
3712 return PhoneFactory.getPhone(phoneId);
3713 }
3714
Shishir Agrawal566b7612013-10-28 14:41:00 -07003715 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003716 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3717 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003718 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3719 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003720 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08003721 if (DBG) {
3722 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3723 }
3724 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
3725 p2);
3726 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003727
Jordan Liu4c733742019-02-28 12:03:40 -08003728
3729 @Override
3730 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
3731 int slotIndex, String callingPackage, String aid, int p2) {
3732 enforceModifyPermission();
3733 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3734 if (DBG) {
3735 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
3736 }
3737 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3738 callingPackage, aid, p2);
3739 }
3740
3741 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
3742 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003743 final long identity = Binder.clearCallingIdentity();
3744 try {
3745 if (TextUtils.equals(ISDR_AID, aid)) {
3746 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003747 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3748 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003749 if (bestComponent == null
3750 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3751 loge("The calling package is not allowed to access ISD-R.");
3752 throw new SecurityException(
3753 "The calling package is not allowed to access ISD-R.");
3754 }
Derek Tan740e1672017-06-27 14:56:27 -07003755 }
Derek Tan740e1672017-06-27 14:56:27 -07003756
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003757 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08003758 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
3759 null /* workSource */);
3760 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003761 return response;
3762 } finally {
3763 Binder.restoreCallingIdentity(identity);
3764 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003765 }
3766
3767 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003768 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003769 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3770 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08003771 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3772 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
3773 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003774
Jordan Liu4c733742019-02-28 12:03:40 -08003775 @Override
3776 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
3777 enforceModifyPermission();
3778 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
3779 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3780 channel);
3781 }
3782
3783 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003784 final long identity = Binder.clearCallingIdentity();
3785 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003786 if (channel < 0) {
3787 return false;
3788 }
Jordan Liu4c733742019-02-28 12:03:40 -08003789 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
3790 null /* workSource */);
3791 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003792 return success;
3793 } finally {
3794 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003795 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003796 }
3797
3798 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003799 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003800 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003801 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3802 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08003803 if (DBG) {
3804 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3805 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3806 + p3 + " data=" + data);
3807 }
3808 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
3809 command, p1, p2, p3, data);
3810 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003811
Jordan Liu4c733742019-02-28 12:03:40 -08003812 @Override
3813 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
3814 int command, int p1, int p2, int p3, String data) {
3815 enforceModifyPermission();
3816 if (DBG) {
3817 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
3818 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3819 + p3 + " data=" + data);
3820 }
3821 return iccTransmitApduLogicalChannelWithPermission(
3822 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
3823 data);
3824 }
3825
3826 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
3827 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003828 final long identity = Binder.clearCallingIdentity();
3829 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07003830 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003831 return "";
3832 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003833
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003834 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08003835 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
3836 null /* workSource */);
3837 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003838
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003839 // Append the returned status code to the end of the response payload.
3840 String s = Integer.toHexString(
3841 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3842 if (response.payload != null) {
3843 s = IccUtils.bytesToHexString(response.payload) + s;
3844 }
3845 return s;
3846 } finally {
3847 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003848 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003849 }
Jake Hambye994d462014-02-03 13:10:13 -08003850
Evan Charltonc66da362014-05-16 14:06:40 -07003851 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003852 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3853 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003854 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3855 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003856 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08003857 if (DBG) {
3858 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3859 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3860 }
3861 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
3862 cla, command, p1, p2, p3, data);
3863 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003864
Jordan Liu4c733742019-02-28 12:03:40 -08003865 @Override
3866 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
3867 int command, int p1, int p2, int p3, String data) {
3868 enforceModifyPermission();
3869 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3870 if (DBG) {
3871 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
3872 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
3873 + " data=" + data);
3874 }
3875
3876 return iccTransmitApduBasicChannelWithPermission(
3877 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
3878 p2, p3, data);
3879 }
3880
3881 // open APDU basic channel assuming the caller has sufficient permissions
3882 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
3883 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003884 final long identity = Binder.clearCallingIdentity();
3885 try {
3886 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3887 && TextUtils.equals(ISDR_AID, data)) {
3888 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003889 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3890 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003891 if (bestComponent == null
3892 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3893 loge("The calling package is not allowed to select ISD-R.");
3894 throw new SecurityException(
3895 "The calling package is not allowed to select ISD-R.");
3896 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003897 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003898
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003899 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08003900 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
3901 null /* workSource */);
3902 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003903
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003904 // Append the returned status code to the end of the response payload.
3905 String s = Integer.toHexString(
3906 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3907 if (response.payload != null) {
3908 s = IccUtils.bytesToHexString(response.payload) + s;
3909 }
3910 return s;
3911 } finally {
3912 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003913 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003914 }
3915
3916 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003917 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003918 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003919 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3920 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003921
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003922 final long identity = Binder.clearCallingIdentity();
3923 try {
3924 if (DBG) {
3925 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3926 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3927 }
3928
3929 IccIoResult response =
3930 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3931 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3932 subId);
3933
3934 if (DBG) {
3935 log("Exchange SIM_IO [R]" + response);
3936 }
3937
3938 byte[] result = null;
3939 int length = 2;
3940 if (response.payload != null) {
3941 length = 2 + response.payload.length;
3942 result = new byte[length];
3943 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3944 } else {
3945 result = new byte[length];
3946 }
3947
3948 result[length - 1] = (byte) response.sw2;
3949 result[length - 2] = (byte) response.sw1;
3950 return result;
3951 } finally {
3952 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003953 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003954 }
3955
Nathan Haroldb3014052017-01-25 15:57:32 -08003956 /**
3957 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3958 * on a particular subscription
3959 */
sqianb6e41952018-03-12 14:54:01 -07003960 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3961 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3962 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3963 return null;
3964 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003965
3966 final long identity = Binder.clearCallingIdentity();
3967 try {
3968 if (appType != TelephonyManager.APPTYPE_USIM
3969 && appType != TelephonyManager.APPTYPE_SIM) {
3970 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3971 return null;
3972 }
3973 Object response = sendRequest(
3974 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3975 if (response instanceof String[]) {
3976 return (String[]) response;
3977 }
3978 // Response is an Exception of some kind,
3979 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003980 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003981 } finally {
3982 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003983 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003984 }
3985
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003986 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003987 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003988 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3989 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003990
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003991 final long identity = Binder.clearCallingIdentity();
3992 try {
3993 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3994 if (response.payload == null) {
3995 return "";
3996 }
Evan Charltonc66da362014-05-16 14:06:40 -07003997
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003998 // Append the returned status code to the end of the response payload.
3999 String s = Integer.toHexString(
4000 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4001 s = IccUtils.bytesToHexString(response.payload) + s;
4002 return s;
4003 } finally {
4004 Binder.restoreCallingIdentity(identity);
4005 }
Evan Charltonc66da362014-05-16 14:06:40 -07004006 }
4007
Jake Hambye994d462014-02-03 13:10:13 -08004008 /**
4009 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4010 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4011 *
4012 * @param itemID the ID of the item to read
4013 * @return the NV item as a String, or null on error.
4014 */
4015 @Override
4016 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004017 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004018 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4019 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004020
4021 final long identity = Binder.clearCallingIdentity();
4022 try {
4023 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004024 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004025 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4026 return value;
4027 } finally {
4028 Binder.restoreCallingIdentity(identity);
4029 }
Jake Hambye994d462014-02-03 13:10:13 -08004030 }
4031
4032 /**
4033 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4034 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4035 *
4036 * @param itemID the ID of the item to read
4037 * @param itemValue the value to write, as a String
4038 * @return true on success; false on any failure
4039 */
4040 @Override
4041 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004042 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004043 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4044 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004045
4046 final long identity = Binder.clearCallingIdentity();
4047 try {
4048 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4049 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004050 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004051 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4052 return success;
4053 } finally {
4054 Binder.restoreCallingIdentity(identity);
4055 }
Jake Hambye994d462014-02-03 13:10:13 -08004056 }
4057
4058 /**
4059 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4060 * Used for device configuration by some CDMA operators.
4061 *
4062 * @param preferredRoamingList byte array containing the new PRL
4063 * @return true on success; false on any failure
4064 */
4065 @Override
4066 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004067 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4068 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004069
4070 final long identity = Binder.clearCallingIdentity();
4071 try {
4072 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4073 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4074 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4075 return success;
4076 } finally {
4077 Binder.restoreCallingIdentity(identity);
4078 }
Jake Hambye994d462014-02-03 13:10:13 -08004079 }
4080
4081 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004082 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004083 * Used for device configuration by some CDMA operators.
4084 *
chen xu6dac5ab2018-10-26 17:39:23 -07004085 * @param slotIndex - device slot.
4086 *
Jake Hambye994d462014-02-03 13:10:13 -08004087 * @return true on success; false on any failure
4088 */
4089 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004090 public boolean resetModemConfig(int slotIndex) {
4091 Phone phone = PhoneFactory.getPhone(slotIndex);
4092 if (phone != null) {
4093 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4094 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004095
chen xu6dac5ab2018-10-26 17:39:23 -07004096 final long identity = Binder.clearCallingIdentity();
4097 try {
4098 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4099 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4100 return success;
4101 } finally {
4102 Binder.restoreCallingIdentity(identity);
4103 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004104 }
chen xu6dac5ab2018-10-26 17:39:23 -07004105 return false;
4106 }
4107
4108 /**
4109 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4110 *
4111 * @param slotIndex - device slot.
4112 *
4113 * @return true on success; false on any failure
4114 */
4115 @Override
4116 public boolean rebootModem(int slotIndex) {
4117 Phone phone = PhoneFactory.getPhone(slotIndex);
4118 if (phone != null) {
4119 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4120 mApp, phone.getSubId(), "rebootModem");
4121
4122 final long identity = Binder.clearCallingIdentity();
4123 try {
4124 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4125 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4126 return success;
4127 } finally {
4128 Binder.restoreCallingIdentity(identity);
4129 }
4130 }
4131 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004132 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004133
Svet Ganovb320e182015-04-16 12:30:10 -07004134 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004135 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004136 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004137 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004138 return new String[0];
4139 }
4140
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004141 final long identity = Binder.clearCallingIdentity();
4142 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004143 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004144 } finally {
4145 Binder.restoreCallingIdentity(identity);
4146 }
Wink Saville36469e72014-06-11 15:17:00 -07004147 }
4148
Brad Ebinger51f743a2017-01-23 13:50:20 -08004149 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004150 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4151 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004152 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004153 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004154 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004155
4156 final long identity = Binder.clearCallingIdentity();
4157 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004158 ImsResolver resolver = PhoneFactory.getImsResolver();
4159 if (resolver == null) {
4160 // may happen if the device does not support IMS.
4161 return;
4162 }
4163 resolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004164 } finally {
4165 Binder.restoreCallingIdentity(identity);
4166 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004167 }
4168
4169 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004170 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4171 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004172 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004173 public void disableIms(int slotId) {
4174 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004175
4176 final long identity = Binder.clearCallingIdentity();
4177 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004178 ImsResolver resolver = PhoneFactory.getImsResolver();
4179 if (resolver == null) {
4180 // may happen if the device does not support IMS.
4181 return;
4182 }
4183 resolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004184 } finally {
4185 Binder.restoreCallingIdentity(identity);
4186 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004187 }
4188
4189 /**
4190 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4191 * feature or {@link null} if the service is not available. If the feature is available, the
4192 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4193 */
4194 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004195 IImsServiceFeatureCallback callback) {
4196 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004197
4198 final long identity = Binder.clearCallingIdentity();
4199 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004200 ImsResolver resolver = PhoneFactory.getImsResolver();
4201 if (resolver == null) {
4202 // may happen if the device does not support IMS.
4203 return null;
4204 }
4205 return resolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004206 } finally {
4207 Binder.restoreCallingIdentity(identity);
4208 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004209 }
4210
4211 /**
4212 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4213 * feature during emergency calling or {@link null} if the service is not available. If the
4214 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4215 * listener for feature updates.
4216 */
4217 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4218 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004219
4220 final long identity = Binder.clearCallingIdentity();
4221 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004222 ImsResolver resolver = PhoneFactory.getImsResolver();
4223 if (resolver == null) {
4224 // may happen if the device does not support IMS.
4225 return null;
4226 }
4227 return resolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004228 } finally {
4229 Binder.restoreCallingIdentity(identity);
4230 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004231 }
4232
Brad Ebinger5f64b052017-12-14 14:26:15 -08004233 /**
4234 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004235 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004236 */
4237 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4238 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004239
4240 final long identity = Binder.clearCallingIdentity();
4241 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004242 ImsResolver resolver = PhoneFactory.getImsResolver();
4243 if (resolver == null) {
4244 // may happen if the device does not support IMS.
4245 return null;
4246 }
4247 return resolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004248 } finally {
4249 Binder.restoreCallingIdentity(identity);
4250 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004251 }
4252
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004253 /**
4254 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004255 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004256 */
4257 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4258 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004259
4260 final long identity = Binder.clearCallingIdentity();
4261 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004262 ImsResolver resolver = PhoneFactory.getImsResolver();
4263 if (resolver == null) {
4264 // may happen if the device does not support IMS.
4265 return null;
4266 }
4267 return resolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004268 } finally {
4269 Binder.restoreCallingIdentity(identity);
4270 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004271 }
4272
Brad Ebinger884c07b2018-02-15 16:17:40 -08004273 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004274 * Sets the ImsService Package Name that Telephony will bind to.
4275 *
4276 * @param slotId the slot ID that the ImsService should bind for.
4277 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4278 * ImsService is the device default ImsService.
4279 * @param packageName The package name of the application that contains the ImsService to bind
4280 * to.
4281 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4282 * @hide
4283 */
4284 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004285 int[] subIds = SubscriptionManager.getSubId(slotId);
4286 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4287 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4288 "setImsService");
4289
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004290 final long identity = Binder.clearCallingIdentity();
4291 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004292 ImsResolver resolver = PhoneFactory.getImsResolver();
4293 if (resolver == null) {
4294 // may happen if the device does not support IMS.
4295 return false;
4296 }
4297 return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService,
4298 packageName);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004299 } finally {
4300 Binder.restoreCallingIdentity(identity);
4301 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004302 }
4303
4304 /**
4305 * Return the ImsService configuration.
4306 *
4307 * @param slotId The slot that the ImsService is associated with.
4308 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4309 * the device default.
4310 * @return the package name of the ImsService configuration.
4311 */
4312 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004313 int[] subIds = SubscriptionManager.getSubId(slotId);
4314 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4315 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4316 "getImsService");
4317
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004318 final long identity = Binder.clearCallingIdentity();
4319 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004320 ImsResolver resolver = PhoneFactory.getImsResolver();
4321 if (resolver == null) {
4322 // may happen if the device does not support IMS.
4323 return "";
4324 }
4325 return resolver.getImsServiceConfiguration(slotId, isCarrierImsService);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004326 } finally {
4327 Binder.restoreCallingIdentity(identity);
4328 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004329 }
4330
Wink Saville36469e72014-06-11 15:17:00 -07004331 public void setImsRegistrationState(boolean registered) {
4332 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004333
4334 final long identity = Binder.clearCallingIdentity();
4335 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004336 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004337 } finally {
4338 Binder.restoreCallingIdentity(identity);
4339 }
Wink Saville36469e72014-06-11 15:17:00 -07004340 }
4341
4342 /**
Stuart Scott54788802015-03-30 13:18:01 -07004343 * Set the network selection mode to automatic.
4344 *
4345 */
4346 @Override
4347 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004348 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4349 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004350
Pengquan Menge92a50d2018-09-21 15:54:48 -07004351 if (!isActiveSubscription(subId)) {
4352 return;
4353 }
4354
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004355 final long identity = Binder.clearCallingIdentity();
4356 try {
4357 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4358 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4359 } finally {
4360 Binder.restoreCallingIdentity(identity);
4361 }
Stuart Scott54788802015-03-30 13:18:01 -07004362 }
4363
Pengquan Mengea84e042018-09-20 14:57:26 -07004364 /**
4365 * Ask the radio to connect to the input network and change selection mode to manual.
4366 *
4367 * @param subId the id of the subscription.
4368 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4369 * the operator to attach to.
4370 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4371 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4372 * normal network selection next time.
4373 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004374 */
4375 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004376 public boolean setNetworkSelectionModeManual(
4377 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004378 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4379 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004380
4381 if (!isActiveSubscription(subId)) {
4382 return false;
4383 }
4384
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004385 final long identity = Binder.clearCallingIdentity();
4386 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004387 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004388 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004389 if (DBG) {
4390 log("setNetworkSelectionModeManual: subId: " + subId
4391 + " operator: " + operatorInfo);
4392 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004393 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4394 } finally {
4395 Binder.restoreCallingIdentity(identity);
4396 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004397 }
4398
4399 /**
4400 * Scans for available networks.
4401 */
4402 @Override
Hall Liuf19c44f2018-11-27 14:38:17 -08004403 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004404 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4405 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004406 LocationAccessPolicy.LocationPermissionResult locationResult =
4407 LocationAccessPolicy.checkLocationPermission(mApp,
4408 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4409 .setCallingPackage(callingPackage)
4410 .setCallingPid(Binder.getCallingPid())
4411 .setCallingUid(Binder.getCallingUid())
4412 .setMethod("getCellNetworkScanResults")
4413 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4414 .build());
4415 switch (locationResult) {
4416 case DENIED_HARD:
4417 throw new SecurityException("Not allowed to access scan results -- location");
4418 case DENIED_SOFT:
4419 return null;
4420 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004421
Pengquan Menga1bb6272018-09-06 09:59:22 -07004422 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004423 try {
4424 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004425 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004426 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004427 } finally {
4428 Binder.restoreCallingIdentity(identity);
4429 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004430 }
4431
4432 /**
yinxub1bed742017-04-17 11:45:04 -07004433 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004434 *
yinxub1bed742017-04-17 11:45:04 -07004435 * @param subId id of the subscription
4436 * @param request contains the radio access networks with bands/channels to scan
4437 * @param messenger callback messenger for scan results or errors
4438 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004439 * @return the id of the requested scan which can be used to stop the scan.
4440 */
4441 @Override
4442 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Hall Liuf19c44f2018-11-27 14:38:17 -08004443 IBinder binder, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004444 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4445 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004446 LocationAccessPolicy.LocationPermissionResult locationResult =
4447 LocationAccessPolicy.checkLocationPermission(mApp,
4448 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4449 .setCallingPackage(callingPackage)
4450 .setCallingPid(Binder.getCallingPid())
4451 .setCallingUid(Binder.getCallingUid())
4452 .setMethod("requestNetworkScan")
4453 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4454 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004455 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07004456 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08004457 if (e != null) {
4458 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4459 throw e;
4460 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07004461 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004462 return TelephonyScanManager.INVALID_SCAN_ID;
4463 }
4464 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004465 }
Hall Liu912dfd32019-04-25 14:02:26 -07004466 int callingUid = Binder.getCallingUid();
4467 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07004468 final long identity = Binder.clearCallingIdentity();
4469 try {
4470 return mNetworkScanRequestTracker.startNetworkScan(
4471 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07004472 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07004473 } finally {
4474 Binder.restoreCallingIdentity(identity);
4475 }
yinxu504e1392017-04-12 16:03:22 -07004476 }
4477
Hall Liub2ac8ef2019-02-28 15:56:23 -08004478 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07004479 NetworkScanRequest request, int subId) {
4480 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
4481 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
4482 boolean hasNetworkScanPermission =
4483 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4484 == PERMISSION_GRANTED;
4485
4486 if (!hasCarrierPriv && !hasNetworkScanPermission) {
4487 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
4488 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08004489 }
4490
4491 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4492 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004493 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4494 return new SecurityException("Specific channels must not be"
4495 + " scanned without location access.");
4496 }
4497 }
4498 }
4499
Hall Liub2ac8ef2019-02-28 15:56:23 -08004500 return null;
4501 }
4502
yinxu504e1392017-04-12 16:03:22 -07004503 /**
4504 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004505 *
4506 * @param subId id of the subscription
4507 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004508 */
4509 @Override
4510 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004511 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4512 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004513
Hall Liu912dfd32019-04-25 14:02:26 -07004514 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004515 final long identity = Binder.clearCallingIdentity();
4516 try {
Hall Liu912dfd32019-04-25 14:02:26 -07004517 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004518 } finally {
4519 Binder.restoreCallingIdentity(identity);
4520 }
yinxu504e1392017-04-12 16:03:22 -07004521 }
4522
4523 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004524 * Get the calculated preferred network type.
4525 * Used for debugging incorrect network type.
4526 *
4527 * @return the preferred network type, defined in RILConstants.java.
4528 */
4529 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004530 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004531 final Phone defaultPhone = getDefaultPhone();
4532 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4533 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004534 return RILConstants.PREFERRED_NETWORK_MODE;
4535 }
4536
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004537 final long identity = Binder.clearCallingIdentity();
4538 try {
4539 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004540 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004541 } finally {
4542 Binder.restoreCallingIdentity(identity);
4543 }
Junda Liu84d15a22014-07-02 11:21:04 -07004544 }
4545
4546 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004547 * Get the preferred network type.
4548 * Used for device configuration by some CDMA operators.
4549 *
4550 * @return the preferred network type, defined in RILConstants.java.
4551 */
4552 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004553 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08004554 TelephonyPermissions
4555 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4556 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004557
4558 final long identity = Binder.clearCallingIdentity();
4559 try {
4560 if (DBG) log("getPreferredNetworkType");
4561 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4562 int networkType = (result != null ? result[0] : -1);
4563 if (DBG) log("getPreferredNetworkType: " + networkType);
4564 return networkType;
4565 } finally {
4566 Binder.restoreCallingIdentity(identity);
4567 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004568 }
4569
4570 /**
4571 * Set the preferred network type.
4572 * Used for device configuration by some CDMA operators.
4573 *
4574 * @param networkType the preferred network type, defined in RILConstants.java.
4575 * @return true on success; false on any failure.
4576 */
4577 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004578 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004579 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4580 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004581
4582 final long identity = Binder.clearCallingIdentity();
4583 try {
4584 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4585 Boolean success = (Boolean) sendRequest(
4586 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4587 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4588 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004589 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004590 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4591 }
4592 return success;
4593 } finally {
4594 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004595 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004596 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004597
4598 /**
Miaoa84611c2019-03-15 09:21:10 +08004599 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004600 *
Miaoa84611c2019-03-15 09:21:10 +08004601 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004602 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004603 * @hide
4604 */
4605 @Override
Miaoa84611c2019-03-15 09:21:10 +08004606 public boolean getTetherApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004607 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004608 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08004609 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004610 try {
Miaoa84611c2019-03-15 09:21:10 +08004611 if (phone != null) {
4612 return phone.hasMatchedTetherApnSetting();
4613 } else {
4614 return false;
4615 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004616 } finally {
4617 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004618 }
Junda Liu475951f2014-11-07 16:45:03 -08004619 }
4620
4621 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004622 * Set mobile data enabled
4623 * Used by the user through settings etc to turn on/off mobile data
4624 *
4625 * @param enable {@code true} turn turn data on, else {@code false}
4626 */
4627 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004628 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004629 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4630 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004631
4632 final long identity = Binder.clearCallingIdentity();
4633 try {
4634 int phoneId = mSubscriptionController.getPhoneId(subId);
4635 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4636 Phone phone = PhoneFactory.getPhone(phoneId);
4637 if (phone != null) {
4638 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08004639 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004640 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004641 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004642 }
4643 } finally {
4644 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004645 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004646 }
4647
4648 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004649 * Get the user enabled state of Mobile Data.
4650 *
4651 * TODO: remove and use isUserDataEnabled.
4652 * This can't be removed now because some vendor codes
4653 * calls through ITelephony directly while they should
4654 * use TelephonyManager.
4655 *
4656 * @return true on enabled
4657 */
4658 @Override
4659 public boolean getDataEnabled(int subId) {
4660 return isUserDataEnabled(subId);
4661 }
4662
4663 /**
4664 * Get whether mobile data is enabled per user setting.
4665 *
4666 * There are other factors deciding whether mobile data is actually enabled, but they are
4667 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004668 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004669 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004670 *
4671 * @return {@code true} if data is enabled else {@code false}
4672 */
4673 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004674 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004675 try {
4676 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4677 null);
4678 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004679 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4680 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004681 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004682
4683 final long identity = Binder.clearCallingIdentity();
4684 try {
4685 int phoneId = mSubscriptionController.getPhoneId(subId);
4686 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4687 Phone phone = PhoneFactory.getPhone(phoneId);
4688 if (phone != null) {
4689 boolean retVal = phone.isUserDataEnabled();
4690 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4691 return retVal;
4692 } else {
4693 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4694 return false;
4695 }
4696 } finally {
4697 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004698 }
4699 }
4700
4701 /**
4702 * Get whether mobile data is enabled.
4703 *
4704 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4705 * whether mobile data is actually enabled.
4706 *
4707 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4708 *
4709 * @return {@code true} if data is enabled else {@code false}
4710 */
4711 @Override
4712 public boolean isDataEnabled(int subId) {
4713 try {
4714 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4715 null);
4716 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004717 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4718 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004719 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004720
4721 final long identity = Binder.clearCallingIdentity();
4722 try {
4723 int phoneId = mSubscriptionController.getPhoneId(subId);
4724 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4725 Phone phone = PhoneFactory.getPhone(phoneId);
4726 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08004727 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004728 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4729 return retVal;
4730 } else {
4731 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4732 return false;
4733 }
4734 } finally {
4735 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004736 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004737 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004738
4739 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004740 public int getCarrierPrivilegeStatus(int subId) {
4741 final Phone phone = getPhone(subId);
4742 if (phone == null) {
4743 loge("getCarrierPrivilegeStatus: Invalid subId");
4744 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4745 }
4746 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004747 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004748 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004749 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4750 }
4751 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004752 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004753 }
Junda Liu29340342014-07-10 15:23:27 -07004754
4755 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004756 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4757 final Phone phone = getPhone(subId);
4758 if (phone == null) {
4759 loge("getCarrierPrivilegeStatus: Invalid subId");
4760 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4761 }
4762 UiccProfile profile =
4763 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4764 if (profile == null) {
4765 loge("getCarrierPrivilegeStatus: No UICC");
4766 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4767 }
4768 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4769 }
4770
4771 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07004772 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
4773 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08004774 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07004775 }
4776
4777 int phoneId = SubscriptionManager.getPhoneId(subId);
4778 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004779 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07004780 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004781 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4782 }
chen xuf7e9fe82019-05-09 19:31:02 -07004783
4784 return card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004785 }
4786
4787 @Override
4788 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004789 if (TextUtils.isEmpty(pkgName))
4790 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004791 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4792 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4793 UiccCard card = UiccController.getInstance().getUiccCard(i);
4794 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004795 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004796 continue;
4797 }
4798
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004799 result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004800 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4801 break;
4802 }
4803 }
4804
4805 return result;
Junda Liu29340342014-07-10 15:23:27 -07004806 }
Derek Tan89e89d42014-07-08 17:00:10 -07004807
4808 @Override
Junda Liue64de782015-04-16 17:19:16 -07004809 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4810 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4811 loge("phoneId " + phoneId + " is not valid.");
4812 return null;
4813 }
4814 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004815 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004816 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004817 return null ;
4818 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004819 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004820 }
4821
Amith Yamasani6e118872016-02-19 12:53:51 -08004822 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07004823 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004824 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08004825 List<String> privilegedPackages = new ArrayList<>();
4826 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07004827 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
4828 // has UICC in that slot.
4829 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08004830 if (card.hasCarrierPrivilegeRules()) {
4831 if (packages == null) {
4832 // Only check packages in user 0 for now
4833 packages = pm.getInstalledPackagesAsUser(
4834 PackageManager.MATCH_DISABLED_COMPONENTS
chen xuf7e9fe82019-05-09 19:31:02 -07004835 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4836 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08004837 }
4838 for (int p = packages.size() - 1; p >= 0; p--) {
4839 PackageInfo pkgInfo = packages.get(p);
4840 if (pkgInfo != null && pkgInfo.packageName != null
4841 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07004842 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08004843 privilegedPackages.add(pkgInfo.packageName);
4844 }
4845 }
4846 }
4847 }
4848 return privilegedPackages;
4849 }
4850
chen xuf7e9fe82019-05-09 19:31:02 -07004851 @Override
4852 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
4853 List<String> privilegedPackages = new ArrayList<>();
4854 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4855 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
4856 }
4857 return privilegedPackages;
4858 }
4859
Wink Savilleb564aae2014-10-23 10:18:09 -07004860 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004861 final Phone phone = getPhone(subId);
4862 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004863 if (card == null) {
4864 loge("getIccId: No UICC");
4865 return null;
4866 }
4867 String iccId = card.getIccId();
4868 if (TextUtils.isEmpty(iccId)) {
4869 loge("getIccId: ICC ID is null or empty.");
4870 return null;
4871 }
4872 return iccId;
4873 }
4874
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004875 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004876 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4877 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004878 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4879 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004880
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004881 final long identity = Binder.clearCallingIdentity();
4882 try {
4883 final String iccId = getIccId(subId);
4884 final Phone phone = getPhone(subId);
4885 if (phone == null) {
4886 return false;
4887 }
4888 final String subscriberId = phone.getSubscriberId();
4889
4890 if (DBG_MERGE) {
4891 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4892 + subscriberId + " to " + number);
4893 }
4894
4895 if (TextUtils.isEmpty(iccId)) {
4896 return false;
4897 }
4898
4899 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4900
4901 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4902 if (alphaTag == null) {
4903 editor.remove(alphaTagPrefKey);
4904 } else {
4905 editor.putString(alphaTagPrefKey, alphaTag);
4906 }
4907
4908 // Record both the line number and IMSI for this ICCID, since we need to
4909 // track all merged IMSIs based on line number
4910 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4911 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4912 if (number == null) {
4913 editor.remove(numberPrefKey);
4914 editor.remove(subscriberPrefKey);
4915 } else {
4916 editor.putString(numberPrefKey, number);
4917 editor.putString(subscriberPrefKey, subscriberId);
4918 }
4919
4920 editor.commit();
4921 return true;
4922 } finally {
4923 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004924 }
Derek Tan7226c842014-07-02 17:42:23 -07004925 }
4926
4927 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004928 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004929 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004930 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004931 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004932 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004933 return null;
4934 }
Derek Tan97ebb422014-09-05 16:55:38 -07004935
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004936 final long identity = Binder.clearCallingIdentity();
4937 try {
4938 String iccId = getIccId(subId);
4939 if (iccId != null) {
4940 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4941 if (DBG_MERGE) {
4942 log("getLine1NumberForDisplay returning "
4943 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4944 }
4945 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004946 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004947 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4948 return null;
4949 } finally {
4950 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004951 }
Derek Tan7226c842014-07-02 17:42:23 -07004952 }
4953
4954 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004955 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004956 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004957 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004958 return null;
4959 }
Derek Tan97ebb422014-09-05 16:55:38 -07004960
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004961 final long identity = Binder.clearCallingIdentity();
4962 try {
4963 String iccId = getIccId(subId);
4964 if (iccId != null) {
4965 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4966 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4967 }
4968 return null;
4969 } finally {
4970 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004971 }
Derek Tan7226c842014-07-02 17:42:23 -07004972 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004973
4974 @Override
Jordan Liub49b04b2019-05-06 14:45:15 -07004975 public String[] getMergedSubscriberIds(int subId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004976 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4977 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004978 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004979 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4980 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004981 return null;
4982 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004983
Jordan Liub49b04b2019-05-06 14:45:15 -07004984 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4985 // the process, where TelephonyManager was instantiated.
4986 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004987 final long identity = Binder.clearCallingIdentity();
4988 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004989 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004990 final TelephonyManager tele = TelephonyManager.from(context);
4991 final SubscriptionManager sub = SubscriptionManager.from(context);
4992
4993 // Figure out what subscribers are currently active
4994 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004995
Jordan Liub49b04b2019-05-06 14:45:15 -07004996 // Only consider subs which match the current subId
4997 // This logic can be simplified. See b/131189269 for progress.
4998 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004999 activeSubscriberIds.add(tele.getSubscriberId(subId));
5000 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005001
5002 // First pass, find a number override for an active subscriber
5003 String mergeNumber = null;
5004 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5005 for (String key : prefs.keySet()) {
5006 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5007 final String subscriberId = (String) prefs.get(key);
5008 if (activeSubscriberIds.contains(subscriberId)) {
5009 final String iccId = key.substring(
5010 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5011 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5012 mergeNumber = (String) prefs.get(numberKey);
5013 if (DBG_MERGE) {
5014 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5015 + " for active subscriber " + subscriberId);
5016 }
5017 if (!TextUtils.isEmpty(mergeNumber)) {
5018 break;
5019 }
5020 }
5021 }
5022 }
5023
5024 // Shortcut when no active merged subscribers
5025 if (TextUtils.isEmpty(mergeNumber)) {
5026 return null;
5027 }
5028
5029 // Second pass, find all subscribers under that line override
5030 final ArraySet<String> result = new ArraySet<>();
5031 for (String key : prefs.keySet()) {
5032 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5033 final String number = (String) prefs.get(key);
5034 if (mergeNumber.equals(number)) {
5035 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5036 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5037 final String subscriberId = (String) prefs.get(subscriberKey);
5038 if (!TextUtils.isEmpty(subscriberId)) {
5039 result.add(subscriberId);
5040 }
5041 }
5042 }
5043 }
5044
5045 final String[] resultArray = result.toArray(new String[result.size()]);
5046 Arrays.sort(resultArray);
5047 if (DBG_MERGE) {
5048 Slog.d(LOG_TAG,
5049 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5050 }
5051 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005052 } finally {
5053 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005054 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005055 }
5056
5057 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005058 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005059 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5060 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005061
5062 final long identity = Binder.clearCallingIdentity();
5063 try {
5064 final Phone phone = getPhone(subId);
5065 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5066 } finally {
5067 Binder.restoreCallingIdentity(identity);
5068 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005069 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005070
5071 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005072 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005073 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5074 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005075 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005076
5077 final long identity = Binder.clearCallingIdentity();
5078 try {
5079 final Phone phone = getPhone(subId);
5080 if (phone == null) {
5081 return false;
5082 }
5083 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5084 cdmaNonRoamingList);
5085 } finally {
5086 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005087 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005088 }
5089
5090 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005091 @Deprecated
5092 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5093 enforceModifyPermission();
5094
5095 int returnValue = 0;
5096 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005097 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005098 if(result.exception == null) {
5099 if (result.result != null) {
5100 byte[] responseData = (byte[])(result.result);
5101 if(responseData.length > oemResp.length) {
5102 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5103 responseData.length + "bytes. Buffer Size is " +
5104 oemResp.length + "bytes.");
5105 }
5106 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5107 returnValue = responseData.length;
5108 }
5109 } else {
5110 CommandException ex = (CommandException) result.exception;
5111 returnValue = ex.getCommandError().ordinal();
5112 if(returnValue > 0) returnValue *= -1;
5113 }
5114 } catch (RuntimeException e) {
5115 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5116 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5117 if(returnValue > 0) returnValue *= -1;
5118 }
5119
5120 return returnValue;
5121 }
5122
5123 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005124 public void setRadioCapability(RadioAccessFamily[] rafs) {
5125 try {
5126 ProxyController.getInstance().setRadioCapability(rafs);
5127 } catch (RuntimeException e) {
5128 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5129 }
5130 }
5131
5132 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005133 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005134 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005135 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005136 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005137 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005138 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005139 final long identity = Binder.clearCallingIdentity();
5140 try {
chen xub97461a2018-10-26 14:17:57 -07005141 TelephonyPermissions
5142 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5143 mApp, phone.getSubId(), "getRadioAccessFamily");
5144 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005145 } finally {
5146 Binder.restoreCallingIdentity(identity);
5147 }
chen xub97461a2018-10-26 14:17:57 -07005148 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005149 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005150
5151 @Override
5152 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005153 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005154 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005155
5156 final long identity = Binder.clearCallingIdentity();
5157 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005158 ImsManager.getInstance(defaultPhone.getContext(),
5159 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005160 } finally {
5161 Binder.restoreCallingIdentity(identity);
5162 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005163 }
5164
5165 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005166 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005167 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00005168 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005169 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005170 return false;
5171 }
Svet Ganovb320e182015-04-16 12:30:10 -07005172
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005173 final long identity = Binder.clearCallingIdentity();
5174 try {
5175 // Check the user preference and the system-level IMS setting. Even if the user has
5176 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5177 // In the long run, we may instead need to check if there exists a connection service
5178 // which can support video calling.
5179 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005180 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005181 return imsManager.isVtEnabledByPlatform()
5182 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5183 && imsManager.isVtEnabledByUser();
5184 } finally {
5185 Binder.restoreCallingIdentity(identity);
5186 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005187 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005188
Andrew Leea1239f22015-03-02 17:44:07 -08005189 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005190 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
5191 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5192 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5193 return false;
5194 }
5195
5196 final long identity = Binder.clearCallingIdentity();
5197 try {
5198 CarrierConfigManager configManager =
5199 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005200 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005201 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5202 } finally {
5203 Binder.restoreCallingIdentity(identity);
5204 }
Andrew Leea1239f22015-03-02 17:44:07 -08005205 }
5206
5207 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005208 public boolean isWorldPhone(int subId, String callingPackage) {
5209 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5210 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5211 return false;
5212 }
5213
5214 final long identity = Binder.clearCallingIdentity();
5215 try {
5216 CarrierConfigManager configManager =
5217 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005218 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005219 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5220 } finally {
5221 Binder.restoreCallingIdentity(identity);
5222 }
Andrew Leea1239f22015-03-02 17:44:07 -08005223 }
5224
Andrew Lee9431b832015-03-09 18:46:45 -07005225 @Override
5226 public boolean isTtyModeSupported() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005227 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005228 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005229 }
5230
5231 @Override
5232 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005233 final long identity = Binder.clearCallingIdentity();
5234 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005235 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005236 } finally {
5237 Binder.restoreCallingIdentity(identity);
5238 }
Andrew Lee9431b832015-03-09 18:46:45 -07005239 }
5240
Hall Liuf6668912018-10-31 17:05:23 -07005241 /**
5242 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5243 * support for the feature and device firmware support.
5244 *
5245 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5246 */
5247 @Override
5248 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005249 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005250 final Phone phone = getPhone(subscriptionId);
5251 if (phone == null) {
5252 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5253 return false;
5254 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005255 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005256 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005257 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5258 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005259 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005260 return isCarrierSupported && isDeviceSupported;
5261 } finally {
5262 Binder.restoreCallingIdentity(identity);
5263 }
Hall Liu98187582018-01-22 19:15:32 -08005264 }
5265
Hall Liuf6668912018-10-31 17:05:23 -07005266 /**
5267 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
5268 * both also support RTT.
5269 */
5270 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005271 final long identity = Binder.clearCallingIdentity();
5272 try {
Hall Liuf6668912018-10-31 17:05:23 -07005273 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005274 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005275 } finally {
5276 Binder.restoreCallingIdentity(identity);
5277 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005278 }
5279
Sanket Padawe7310cc72015-01-14 09:53:20 -08005280 /**
5281 * Returns the unique device ID of phone, for example, the IMEI for
5282 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5283 *
5284 * <p>Requires Permission:
5285 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5286 */
5287 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005288 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005289 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005290 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005291 return null;
5292 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005293 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005294 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
5295 callingPackage, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005296 return null;
5297 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005298
5299 final long identity = Binder.clearCallingIdentity();
5300 try {
5301 return phone.getDeviceId();
5302 } finally {
5303 Binder.restoreCallingIdentity(identity);
5304 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005305 }
5306
Ping Sunc67b7c22016-03-02 19:16:45 +08005307 /**
5308 * {@hide}
5309 * Returns the IMS Registration Status on a particular subid
5310 *
5311 * @param subId
5312 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005313 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005314 Phone phone = getPhone(subId);
5315 if (phone != null) {
5316 return phone.isImsRegistered();
5317 } else {
5318 return false;
5319 }
5320 }
5321
Santos Cordon7a1885b2015-02-03 11:15:19 -08005322 @Override
5323 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005324 final long identity = Binder.clearCallingIdentity();
5325 try {
5326 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5327 } finally {
5328 Binder.restoreCallingIdentity(identity);
5329 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005330 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005331
Tyler Gunnf70ed162019-04-03 15:28:53 -07005332 @Override
5333 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5334 final long identity = Binder.clearCallingIdentity();
5335 try {
5336 Phone phone = getPhone(subscriptionId);
5337 if (phone == null) {
5338 return null;
5339 }
5340 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5341 } finally {
5342 Binder.restoreCallingIdentity(identity);
5343 }
5344 }
5345
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005346 /**
5347 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005348 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005349 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005350 final long identity = Binder.clearCallingIdentity();
5351 try {
5352 Phone phone = getPhone(subId);
5353 if (phone != null) {
5354 return phone.isWifiCallingEnabled();
5355 } else {
5356 return false;
5357 }
5358 } finally {
5359 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005360 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005361 }
5362
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005363 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005364 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005365 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005366 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005367 final long identity = Binder.clearCallingIdentity();
5368 try {
5369 Phone phone = getPhone(subId);
5370 if (phone != null) {
5371 return phone.isVideoEnabled();
5372 } else {
5373 return false;
5374 }
5375 } finally {
5376 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005377 }
5378 }
5379
5380 /**
5381 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5382 * defined in {@link ImsRegistrationImplBase}.
5383 */
5384 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005385 final long identity = Binder.clearCallingIdentity();
5386 try {
5387 Phone phone = getPhone(subId);
5388 if (phone != null) {
5389 return phone.getImsRegistrationTech();
5390 } else {
5391 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5392 }
5393 } finally {
5394 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005395 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005396 }
5397
Stuart Scott8eef64f2015-04-08 15:13:54 -07005398 @Override
5399 public void factoryReset(int subId) {
5400 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005401 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5402 return;
5403 }
5404
Svet Ganovcc087f82015-05-12 20:35:54 -07005405 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005406
Svet Ganovcc087f82015-05-12 20:35:54 -07005407 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005408 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5409 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005410 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005411 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005412 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005413 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5414 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005415 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005416 // There has been issues when Sms raw table somehow stores orphan
5417 // fragments. They lead to garbled message when new fragments come
5418 // in and combined with those stale ones. In case this happens again,
5419 // user can reset all network settings which will clean up this table.
5420 cleanUpSmsRawTable(getDefaultPhone().getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07005421 } finally {
5422 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005423 }
5424 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005425
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005426 private void cleanUpSmsRawTable(Context context) {
5427 ContentResolver resolver = context.getContentResolver();
5428 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5429 resolver.delete(uri, null, null);
5430 }
5431
Narayan Kamath1c496c22015-04-16 14:40:19 +01005432 @Override
chen xu5d3637b2019-01-21 23:31:38 -08005433 public String getSimLocaleForSubscriber(int subId) {
5434 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5435 final Phone phone = getPhone(subId);
5436 if (phone == null) {
5437 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08005438 return null;
chen xu5d3637b2019-01-21 23:31:38 -08005439 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005440 final long identity = Binder.clearCallingIdentity();
5441 try {
chen xu5d3637b2019-01-21 23:31:38 -08005442 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5443 phone.getContext().getOpPackageName());
chen xu6291c472019-02-04 12:55:53 -08005444 if (info == null) {
5445 log("getSimLocaleForSubscriber, inactive subId: " + subId);
5446 return null;
5447 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005448 // Try and fetch the locale from the carrier properties or from the SIM language
5449 // preferences (EF-PL and EF-LI)...
5450 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005451 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08005452 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5453 if (localeFromDefaultSim != null) {
5454 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5455 if (DBG) log("Using locale from subId: " + subId + " locale: "
5456 + localeFromDefaultSim);
5457 return localeFromDefaultSim.toLanguageTag();
5458 } else {
5459 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005460 }
5461 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005462
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005463 // The SIM language preferences only store a language (e.g. fr = French), not an
5464 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5465 // the SIM and carrier preferences does not include a country we add the country
5466 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005467 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005468 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08005469 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005470 return mccLocale.toLanguageTag();
5471 }
5472
5473 if (DBG) log("No locale found - returning null");
5474 return null;
5475 } finally {
5476 Binder.restoreCallingIdentity(identity);
5477 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005478 }
5479
5480 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005481 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005482 }
5483
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005484 /**
5485 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5486 */
5487 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005488 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005489 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005490
Chenjie Yu1ba97252018-01-11 18:16:20 -08005491 private final ModemActivityInfo mLastModemActivityInfo =
5492 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
5493
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005494 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005495 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5496 * representing the state of the modem.
5497 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005498 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5499 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005500 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005501 */
5502 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005503 public void requestModemActivityInfo(ResultReceiver result) {
5504 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005505 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005506
5507 final long identity = Binder.clearCallingIdentity();
5508 try {
5509 ModemActivityInfo ret = null;
5510 synchronized (mLastModemActivityInfo) {
5511 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5512 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07005513 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07005514 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005515 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
5516 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005517 mergedTxTimeMs[i] = info.getTxTimeMillis()[i]
5518 + mLastModemActivityInfo.getTxTimeMillis()[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005519 }
5520 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005521 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
5522 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005523 mLastModemActivityInfo.setIdleTimeMillis(
5524 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
5525 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
5526 mLastModemActivityInfo.setRxTimeMillis(
5527 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
5528 mLastModemActivityInfo.setEnergyUsed(
5529 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005530 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005531 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
5532 mLastModemActivityInfo.getSleepTimeMillis(),
5533 mLastModemActivityInfo.getIdleTimeMillis(),
5534 mLastModemActivityInfo.getTxTimeMillis(),
5535 mLastModemActivityInfo.getRxTimeMillis(),
5536 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005537 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005538 Bundle bundle = new Bundle();
5539 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
5540 result.send(0, bundle);
5541 } finally {
5542 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005543 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005544 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005545
Siddharth Rayb8114062018-06-17 15:02:38 -07005546 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
5547 // less than total activity duration.
5548 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
5549 if (info == null) {
5550 return false;
5551 }
5552 int activityDurationMs =
5553 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
5554 int totalTxTimeMs = 0;
5555 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
5556 totalTxTimeMs += info.getTxTimeMillis()[i];
5557 }
5558 return (info.isValid()
5559 && (info.getSleepTimeMillis() <= activityDurationMs)
5560 && (info.getIdleTimeMillis() <= activityDurationMs)
5561 && (info.getRxTimeMillis() <= activityDurationMs)
5562 && (totalTxTimeMs <= activityDurationMs));
5563 }
5564
Jack Yu85bd38a2015-11-09 11:34:32 -08005565 /**
5566 * {@hide}
5567 * Returns the service state information on specified subscription.
5568 */
5569 @Override
5570 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005571 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005572 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08005573 return null;
5574 }
5575
Hall Liuf19c44f2018-11-27 14:38:17 -08005576 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
5577 LocationAccessPolicy.checkLocationPermission(mApp,
5578 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5579 .setCallingPackage(callingPackage)
5580 .setCallingPid(Binder.getCallingPid())
5581 .setCallingUid(Binder.getCallingUid())
5582 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07005583 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005584 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5585 .build());
5586
5587 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
5588 LocationAccessPolicy.checkLocationPermission(mApp,
5589 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5590 .setCallingPackage(callingPackage)
5591 .setCallingPid(Binder.getCallingPid())
5592 .setCallingUid(Binder.getCallingUid())
5593 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07005594 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005595 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5596 .build());
5597 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
5598 boolean hasFinePermission =
5599 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5600 boolean hasCoarsePermission =
5601 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5602
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005603 final long identity = Binder.clearCallingIdentity();
5604 try {
5605 final Phone phone = getPhone(subId);
5606 if (phone == null) {
5607 return null;
5608 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005609
Hall Liuf19c44f2018-11-27 14:38:17 -08005610 ServiceState ss = phone.getServiceState();
5611
5612 // Scrub out the location info in ServiceState depending on what level of access
5613 // the caller has.
5614 if (hasFinePermission) return ss;
5615 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
5616 return ss.sanitizeLocationInfo(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005617 } finally {
5618 Binder.restoreCallingIdentity(identity);
5619 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005620 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005621
5622 /**
5623 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
5624 *
5625 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5626 * voicemail ringtone.
5627 * @return The URI for the ringtone to play when receiving a voicemail from a specific
5628 * PhoneAccount.
5629 */
5630 @Override
5631 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005632 final long identity = Binder.clearCallingIdentity();
5633 try {
5634 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5635 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005636 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005637 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005638
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005639 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
5640 } finally {
5641 Binder.restoreCallingIdentity(identity);
5642 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005643 }
5644
5645 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005646 * Sets the per-account voicemail ringtone.
5647 *
5648 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5649 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5650 *
5651 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5652 * voicemail ringtone.
5653 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5654 * PhoneAccount.
5655 */
5656 @Override
5657 public void setVoicemailRingtoneUri(String callingPackage,
5658 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005659 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005660 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5661 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005662 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005663 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5664 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5665 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005666 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005667
5668 final long identity = Binder.clearCallingIdentity();
5669 try {
5670 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5671 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005672 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005673 }
5674 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5675 } finally {
5676 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005677 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005678 }
5679
5680 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005681 * Returns whether vibration is set for voicemail notification in Phone settings.
5682 *
5683 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5684 * voicemail vibration setting.
5685 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5686 */
5687 @Override
5688 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005689 final long identity = Binder.clearCallingIdentity();
5690 try {
5691 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5692 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005693 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005694 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005695
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005696 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5697 } finally {
5698 Binder.restoreCallingIdentity(identity);
5699 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005700 }
5701
Youhan Wange64578a2016-05-02 15:32:42 -07005702 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005703 * Sets the per-account voicemail vibration.
5704 *
5705 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5706 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5707 *
5708 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5709 * voicemail vibration setting.
5710 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5711 * specific PhoneAccount.
5712 */
5713 @Override
5714 public void setVoicemailVibrationEnabled(String callingPackage,
5715 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005716 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005717 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5718 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005719 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005720 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5721 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5722 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005723 }
5724
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005725 final long identity = Binder.clearCallingIdentity();
5726 try {
5727 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5728 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005729 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005730 }
5731 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5732 } finally {
5733 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005734 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005735 }
5736
5737 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005738 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5739 *
5740 * @throws SecurityException if the caller does not have the required permission
5741 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005742 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005743 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07005744 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005745 }
5746
5747 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005748 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5749 * permission.
5750 *
5751 * @throws SecurityException if the caller does not have the required permission
5752 */
5753 private void enforceSendSmsPermission() {
5754 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5755 }
5756
5757 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005758 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005759 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005760 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005761 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005762 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005763 final long identity = Binder.clearCallingIdentity();
5764 try {
5765 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005766 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005767 if (componentName == null) {
5768 throw new SecurityException(
5769 "Caller not current active visual voicemail package[null]");
5770 }
5771 String vvmPackage = componentName.getPackageName();
5772 if (!callingPackage.equals(vvmPackage)) {
5773 throw new SecurityException("Caller not current active visual voicemail package["
5774 + vvmPackage + "]");
5775 }
5776 } finally {
5777 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005778 }
5779 }
5780
5781 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005782 * Return the application ID for the app type.
5783 *
5784 * @param subId the subscription ID that this request applies to.
5785 * @param appType the uicc app type.
5786 * @return Application ID for specificied app type, or null if no uicc.
5787 */
5788 @Override
5789 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005790 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005791 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005792
5793 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005794 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005795 if (phone == null) {
5796 return null;
5797 }
5798 String aid = null;
5799 try {
5800 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5801 .getApplicationByType(appType).getAid();
5802 } catch (Exception e) {
5803 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5804 }
5805 return aid;
5806 } finally {
5807 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005808 }
Youhan Wange64578a2016-05-02 15:32:42 -07005809 }
5810
Youhan Wang4001d252016-05-11 10:29:41 -07005811 /**
5812 * Return the Electronic Serial Number.
5813 *
5814 * @param subId the subscription ID that this request applies to.
5815 * @return ESN or null if error.
5816 */
5817 @Override
5818 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005819 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005820 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005821
5822 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005823 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005824 if (phone == null) {
5825 return null;
5826 }
5827 String esn = null;
5828 try {
5829 esn = phone.getEsn();
5830 } catch (Exception e) {
5831 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5832 }
5833 return esn;
5834 } finally {
5835 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005836 }
Youhan Wang4001d252016-05-11 10:29:41 -07005837 }
5838
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005839 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005840 * Return the Preferred Roaming List Version.
5841 *
5842 * @param subId the subscription ID that this request applies to.
5843 * @return PRLVersion or null if error.
5844 */
5845 @Override
5846 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005847 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005848 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005849
5850 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005851 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005852 if (phone == null) {
5853 return null;
5854 }
5855 String cdmaPrlVersion = null;
5856 try {
5857 cdmaPrlVersion = phone.getCdmaPrlVersion();
5858 } catch (Exception e) {
5859 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5860 }
5861 return cdmaPrlVersion;
5862 } finally {
5863 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005864 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005865 }
5866
5867 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005868 * Get snapshot of Telephony histograms
5869 * @return List of Telephony histograms
5870 * @hide
5871 */
5872 @Override
5873 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005874 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5875 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005876
5877 final long identity = Binder.clearCallingIdentity();
5878 try {
5879 return RIL.getTelephonyRILTimingHistograms();
5880 } finally {
5881 Binder.restoreCallingIdentity(identity);
5882 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005883 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005884
5885 /**
5886 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08005887 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
5888 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005889 * Require system privileges. In the future we may add this to carrier APIs.
5890 *
Michele Berionne482f8202018-11-27 18:57:59 -08005891 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005892 */
5893 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08005894 @TelephonyManager.SetCarrierRestrictionResult
5895 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005896 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005897 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005898
Michele Berionne482f8202018-11-27 18:57:59 -08005899 if (carrierRestrictionRules == null) {
5900 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08005901 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005902
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005903 final long identity = Binder.clearCallingIdentity();
5904 try {
Michele Berionne482f8202018-11-27 18:57:59 -08005905 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07005906 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005907 } finally {
5908 Binder.restoreCallingIdentity(identity);
5909 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005910 }
5911
5912 /**
5913 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08005914 * Get the allowed carrier list and the excluded carrier list, including the priority between
5915 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005916 * Require system privileges. In the future we may add this to carrier APIs.
5917 *
Michele Berionne482f8202018-11-27 18:57:59 -08005918 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07005919 */
5920 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08005921 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005922 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07005923 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005924
5925 final long identity = Binder.clearCallingIdentity();
5926 try {
Michele Berionne482f8202018-11-27 18:57:59 -08005927 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
5928 if (response instanceof CarrierRestrictionRules) {
5929 return (CarrierRestrictionRules) response;
5930 }
5931 // Response is an Exception of some kind,
5932 // which is signalled to the user as a NULL retval
5933 return null;
5934 } catch (Exception e) {
5935 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
5936 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005937 } finally {
5938 Binder.restoreCallingIdentity(identity);
5939 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005940 }
5941
fionaxu59545b42016-05-25 15:53:37 -07005942 /**
5943 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5944 * @param subId the subscription ID that this action applies to.
5945 * @param enabled control enable or disable metered apns.
5946 * {@hide}
5947 */
5948 @Override
5949 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5950 enforceModifyPermission();
5951 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005952
5953 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005954 if (phone == null) {
5955 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5956 return;
5957 }
5958 try {
5959 phone.carrierActionSetMeteredApnsEnabled(enabled);
5960 } catch (Exception e) {
5961 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005962 } finally {
5963 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005964 }
5965 }
5966
5967 /**
5968 * Action set from carrier signalling broadcast receivers to enable/disable radio
5969 * @param subId the subscription ID that this action applies to.
5970 * @param enabled control enable or disable radio.
5971 * {@hide}
5972 */
5973 @Override
5974 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5975 enforceModifyPermission();
5976 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005977
5978 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005979 if (phone == null) {
5980 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5981 return;
5982 }
5983 try {
5984 phone.carrierActionSetRadioEnabled(enabled);
5985 } catch (Exception e) {
5986 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005987 } finally {
5988 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005989 }
5990 }
5991
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005992 /**
fionaxu8da9cb12017-05-23 15:02:46 -07005993 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
5994 * network status based on which carrier apps could apply actions accordingly,
5995 * enable/disable default url handler for example.
5996 *
5997 * @param subId the subscription ID that this action applies to.
5998 * @param report control start/stop reporting the default network status.
5999 * {@hide}
6000 */
6001 @Override
6002 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6003 enforceModifyPermission();
6004 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006005
6006 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006007 if (phone == null) {
6008 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6009 return;
6010 }
6011 try {
6012 phone.carrierActionReportDefaultNetworkStatus(report);
6013 } catch (Exception e) {
6014 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006015 } finally {
6016 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006017 }
6018 }
6019
6020 /**
fionaxud9622282017-07-17 17:51:30 -07006021 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6022 * @param subId the subscription ID that this action applies to.
6023 * {@hide}
6024 */
6025 @Override
6026 public void carrierActionResetAll(int subId) {
6027 enforceModifyPermission();
6028 final Phone phone = getPhone(subId);
6029 if (phone == null) {
6030 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6031 return;
6032 }
6033 try {
6034 phone.carrierActionResetAll();
6035 } catch (Exception e) {
6036 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6037 }
6038 }
6039
6040 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006041 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6042 * bug report is being generated.
6043 */
6044 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006045 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006046 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6047 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006048 writer.println("Permission Denial: can't dump Phone from pid="
6049 + Binder.getCallingPid()
6050 + ", uid=" + Binder.getCallingUid()
6051 + "without permission "
6052 + android.Manifest.permission.DUMP);
6053 return;
6054 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006055 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006056 }
Jack Yueb89b242016-06-22 13:27:47 -07006057
Brad Ebingerdac2f002018-04-03 15:17:52 -07006058 @Override
6059 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6060 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6061 throws RemoteException {
6062 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
6063 }
6064
Jack Yueb89b242016-06-22 13:27:47 -07006065 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006066 * Get aggregated video call data usage since boot.
6067 *
6068 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6069 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006070 * {@hide}
6071 */
6072 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006073 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006074 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6075 null);
6076
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006077 final long identity = Binder.clearCallingIdentity();
6078 try {
6079 // NetworkStatsService keeps tracking the active network interface and identity. It
6080 // records the delta with the corresponding network identity.
6081 // We just return the total video call data usage snapshot since boot.
6082 Phone phone = getPhone(subId);
6083 if (phone != null) {
6084 return phone.getVtDataUsage(perUidStats);
6085 }
6086 return null;
6087 } finally {
6088 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006089 }
Jack Yueb89b242016-06-22 13:27:47 -07006090 }
Jack Yu75ab2952016-07-08 14:29:33 -07006091
6092 /**
6093 * Policy control of data connection. Usually used when data limit is passed.
6094 * @param enabled True if enabling the data, otherwise disabling.
6095 * @param subId Subscription index
6096 * {@hide}
6097 */
6098 @Override
6099 public void setPolicyDataEnabled(boolean enabled, int subId) {
6100 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006101
6102 final long identity = Binder.clearCallingIdentity();
6103 try {
6104 Phone phone = getPhone(subId);
6105 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006106 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006107 }
6108 } finally {
6109 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006110 }
6111 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006112
6113 /**
6114 * Get Client request stats
6115 * @return List of Client Request Stats
6116 * @hide
6117 */
6118 @Override
6119 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006120 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006121 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006122 return null;
6123 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006124 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006125
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006126 final long identity = Binder.clearCallingIdentity();
6127 try {
6128 if (phone != null) {
6129 return phone.getClientRequestStats();
6130 }
6131
6132 return null;
6133 } finally {
6134 Binder.restoreCallingIdentity(identity);
6135 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006136 }
6137
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006138 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006139 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006140 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006141 }
Jack Yueb4124c2017-02-16 15:32:43 -08006142
6143 /**
Grace Chen70990072017-03-24 17:21:30 -07006144 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006145 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006146 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006147 * @param state State of SIM (power down, power up, pass through)
6148 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6149 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6150 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006151 *
6152 **/
6153 @Override
Grace Chen70990072017-03-24 17:21:30 -07006154 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006155 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006156 Phone phone = PhoneFactory.getPhone(slotIndex);
6157
vagdeviaf9a5b92018-08-15 16:01:53 -07006158 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6159
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006160 final long identity = Binder.clearCallingIdentity();
6161 try {
6162 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006163 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006164 }
6165 } finally {
6166 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006167 }
6168 }
Shuo Qiandd210312017-04-12 22:11:33 +00006169
Tyler Gunn65d45c22017-06-05 11:22:26 -07006170 private boolean isUssdApiAllowed(int subId) {
6171 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006172 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006173 if (configManager == null) {
6174 return false;
6175 }
6176 PersistableBundle pb = configManager.getConfigForSubId(subId);
6177 if (pb == null) {
6178 return false;
6179 }
6180 return pb.getBoolean(
6181 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6182 }
6183
Shuo Qiandd210312017-04-12 22:11:33 +00006184 /**
6185 * Check if phone is in emergency callback mode
6186 * @return true if phone is in emergency callback mode
6187 * @param subId sub id
6188 */
goneil9c5f4872017-12-05 14:07:56 -08006189 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006190 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006191 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006192 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006193
6194 final long identity = Binder.clearCallingIdentity();
6195 try {
6196 if (phone != null) {
6197 return phone.isInEcm();
6198 } else {
6199 return false;
6200 }
6201 } finally {
6202 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006203 }
6204 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006205
6206 /**
6207 * Get the current signal strength information for the given subscription.
6208 * Because this information is not updated when the device is in a low power state
6209 * it should not be relied-upon to be current.
6210 * @param subId Subscription index
6211 * @return the most recent cached signal strength info from the modem
6212 */
6213 @Override
6214 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006215 final long identity = Binder.clearCallingIdentity();
6216 try {
6217 Phone p = getPhone(subId);
6218 if (p == null) {
6219 return null;
6220 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006221
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006222 return p.getSignalStrength();
6223 } finally {
6224 Binder.restoreCallingIdentity(identity);
6225 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006226 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006227
Pengquan Meng77b7f132018-08-22 14:49:57 -07006228 /**
Chen Xuf792fd62018-10-17 17:54:36 +00006229 * Get the current modem radio state for the given slot.
6230 * @param slotIndex slot index.
6231 * @param callingPackage the name of the package making the call.
6232 * @return the current radio power state from the modem
6233 */
6234 @Override
6235 public int getRadioPowerState(int slotIndex, String callingPackage) {
6236 Phone phone = PhoneFactory.getPhone(slotIndex);
6237 if (phone != null) {
6238 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6239 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
6240 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6241 }
6242
6243 final long identity = Binder.clearCallingIdentity();
6244 try {
6245 return phone.getRadioPowerState();
6246 } finally {
6247 Binder.restoreCallingIdentity(identity);
6248 }
6249 }
6250 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6251 }
6252
6253 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07006254 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6255 *
6256 * <p>Requires one of the following permissions:
6257 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6258 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6259 * privileges.
6260 *
6261 * @param subId subscription id
6262 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6263 * {@code false}.
6264 */
6265 @Override
6266 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006267 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6268 null /* message */);
6269
Pengquan Menga1bb6272018-09-06 09:59:22 -07006270 boolean isEnabled = false;
6271 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07006272 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006273 Phone phone = getPhone(subId);
6274 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006275 } catch (Exception e) {
6276 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6277 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07006278 } finally {
6279 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006280 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006281 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006282 }
6283
6284
6285 /**
6286 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6287 *
6288 * <p> Requires permission:
6289 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6290 * privileges.
6291 *
6292 * @param subId subscription id
6293 * @param isEnabled {@code true} means enable, {@code false} means disable.
6294 */
6295 @Override
6296 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006297 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6298 mApp, subId, "setDataRoamingEnabled");
6299
Pengquan Menga1bb6272018-09-06 09:59:22 -07006300 final long identity = Binder.clearCallingIdentity();
6301 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006302 Phone phone = getPhone(subId);
6303 if (phone != null) {
6304 phone.setDataRoamingEnabled(isEnabled);
6305 }
6306 } finally {
6307 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006308 }
6309 }
6310
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006311 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006312 public boolean isManualNetworkSelectionAllowed(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006313 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6314 mApp, subId, "isManualNetworkSelectionAllowed");
6315
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006316 boolean isAllowed = true;
6317 final long identity = Binder.clearCallingIdentity();
6318 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006319 Phone phone = getPhone(subId);
6320 if (phone != null) {
6321 isAllowed = phone.isCspPlmnEnabled();
6322 }
6323 } finally {
6324 Binder.restoreCallingIdentity(identity);
6325 }
6326 return isAllowed;
6327 }
6328
6329 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006330 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu262519f2020-03-23 11:55:07 -07006331 // Verify that tha callingPackage belongs to the calling UID
6332 mApp.getSystemService(AppOpsManager.class)
6333 .checkPackage(Binder.getCallingUid(), callingPackage);
6334
Jordan Liu1e142fc2019-04-22 15:10:43 -07006335 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08006336 try {
6337 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07006338 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08006339 } catch (SecurityException e) {
6340 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6341 // has carrier privileges on an active UICC
6342 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6343 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006344 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08006345 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006346 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006347
6348 final long identity = Binder.clearCallingIdentity();
6349 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006350 UiccController uiccController = UiccController.getInstance();
6351 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07006352 if (hasReadPermission) {
6353 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006354 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07006355
6356 // Remove private info if the caller doesn't have access
6357 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6358 for (UiccCardInfo cardInfo : cardInfos) {
6359 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6360 // is available
6361 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
6362 if (card == null || card.getUiccProfile() == null) {
6363 // assume no access if the card or profile is unavailable
6364 filteredInfos.add(cardInfo.getUnprivileged());
6365 continue;
6366 }
6367 UiccProfile profile = card.getUiccProfile();
6368 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6369 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6370 filteredInfos.add(cardInfo);
6371 } else {
6372 filteredInfos.add(cardInfo.getUnprivileged());
6373 }
6374 }
6375 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08006376 } finally {
6377 Binder.restoreCallingIdentity(identity);
6378 }
6379 }
6380
6381 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006382 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006383 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006384
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006385 final long identity = Binder.clearCallingIdentity();
6386 try {
6387 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6388 if (slots == null) {
6389 Rlog.i(LOG_TAG, "slots is null.");
6390 return null;
6391 }
6392
6393 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6394 for (int i = 0; i < slots.length; i++) {
6395 UiccSlot slot = slots[i];
6396 if (slot == null) {
6397 continue;
6398 }
6399
Jordan Liu7be7e652019-05-06 18:55:02 +00006400 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006401 UiccCard card = slot.getUiccCard();
6402 if (card != null) {
6403 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00006404 } else {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006405 cardId = slot.getIccId();
6406 }
6407
6408 int cardState = 0;
6409 switch (slot.getCardState()) {
6410 case CARDSTATE_ABSENT:
6411 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6412 break;
6413 case CARDSTATE_PRESENT:
6414 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6415 break;
6416 case CARDSTATE_ERROR:
6417 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6418 break;
6419 case CARDSTATE_RESTRICTED:
6420 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6421 break;
6422 default:
6423 break;
6424
6425 }
6426
6427 infos[i] = new UiccSlotInfo(
6428 slot.isActive(),
6429 slot.isEuicc(),
6430 cardId,
6431 cardState,
6432 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08006433 slot.isExtendedApduSupported(),
6434 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006435 }
6436 return infos;
6437 } finally {
6438 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006439 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006440 }
6441
6442 @Override
6443 public boolean switchSlots(int[] physicalSlots) {
6444 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006445
6446 final long identity = Binder.clearCallingIdentity();
6447 try {
6448 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6449 } finally {
6450 Binder.restoreCallingIdentity(identity);
6451 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006452 }
Jack Yu4c988042018-02-27 15:30:01 -08006453
6454 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006455 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006456 final long identity = Binder.clearCallingIdentity();
6457 try {
6458 return UiccController.getInstance().getCardIdForDefaultEuicc();
6459 } finally {
6460 Binder.restoreCallingIdentity(identity);
6461 }
6462 }
6463
6464 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006465 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6466 enforceModifyPermission();
6467 final Phone phone = getPhone(subId);
6468 if (phone == null) {
6469 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6470 return;
6471 }
6472
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006473 final long identity = Binder.clearCallingIdentity();
6474 try {
6475 phone.setRadioIndicationUpdateMode(filters, mode);
6476 } finally {
6477 Binder.restoreCallingIdentity(identity);
6478 }
Jack Yu4c988042018-02-27 15:30:01 -08006479 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006480
6481 /**
goneil47ffb6e2018-04-06 15:40:58 -07006482 * A test API to reload the UICC profile.
6483 *
6484 * <p>Requires that the calling app has permission
6485 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6486 * @hide
6487 */
6488 @Override
6489 public void refreshUiccProfile(int subId) {
6490 enforceModifyPermission();
6491
6492 final long identity = Binder.clearCallingIdentity();
6493 try {
6494 Phone phone = getPhone(subId);
6495 if (phone == null) {
6496 return;
6497 }
6498 UiccCard uiccCard = phone.getUiccCard();
6499 if (uiccCard == null) {
6500 return;
6501 }
6502 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6503 if (uiccProfile == null) {
6504 return;
6505 }
6506 uiccProfile.refresh();
6507 } finally {
6508 Binder.restoreCallingIdentity(identity);
6509 }
6510 }
6511
6512 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006513 * Returns false if the mobile data is disabled by default, otherwise return true.
6514 */
6515 private boolean getDefaultDataEnabled() {
6516 return "true".equalsIgnoreCase(
6517 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
6518 }
6519
6520 /**
6521 * Returns true if the data roaming is enabled by default, i.e the system property
6522 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
6523 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
6524 */
6525 private boolean getDefaultDataRoamingEnabled(int subId) {
6526 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006527 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006528 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
6529 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
6530 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
6531 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
6532 return isDataRoamingEnabled;
6533 }
6534
6535 /**
6536 * Returns the default network type for the given {@code subId}, if the default network type is
6537 * not set, return {@link Phone#PREFERRED_NT_MODE}.
6538 */
6539 private int getDefaultNetworkType(int subId) {
6540 return Integer.parseInt(
6541 TelephonyManager.getTelephonyProperty(
6542 mSubscriptionController.getPhoneId(subId),
6543 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
6544 String.valueOf(Phone.PREFERRED_NT_MODE)));
6545 }
fionaxua13278b2018-03-21 00:08:13 -07006546
6547 @Override
6548 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07006549 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07006550 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006551
6552 final long identity = Binder.clearCallingIdentity();
6553 try {
6554 final Phone phone = getPhone(subId);
6555 if (phone == null) {
6556 loge("setCarrierTestOverride fails with invalid subId: " + subId);
6557 return;
6558 }
chen xueaba88a2019-03-15 13:15:10 -07006559 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
6560 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006561 } finally {
6562 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006563 }
fionaxua13278b2018-03-21 00:08:13 -07006564 }
6565
6566 @Override
6567 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006568 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006569
6570 final long identity = Binder.clearCallingIdentity();
6571 try {
6572 final Phone phone = getPhone(subId);
6573 if (phone == null) {
6574 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
6575 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
6576 }
6577 return phone.getCarrierIdListVersion();
6578 } finally {
6579 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006580 }
fionaxua13278b2018-03-21 00:08:13 -07006581 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07006582
6583 @Override
6584 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
6585 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6586 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
6587 return -1;
6588 }
6589
6590 final long identity = Binder.clearCallingIdentity();
6591 try {
6592 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
6593 } finally {
6594 Binder.restoreCallingIdentity(identity);
6595 }
6596 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006597
6598 @Override
6599 public int getCdmaRoamingMode(int subId) {
6600 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6601 mApp, subId, "getCdmaRoamingMode");
6602
6603 final long identity = Binder.clearCallingIdentity();
6604 try {
6605 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
6606 } finally {
6607 Binder.restoreCallingIdentity(identity);
6608 }
6609 }
6610
6611 @Override
6612 public boolean setCdmaRoamingMode(int subId, int mode) {
6613 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6614 mApp, subId, "setCdmaRoamingMode");
6615
6616 final long identity = Binder.clearCallingIdentity();
6617 try {
6618 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
6619 } finally {
6620 Binder.restoreCallingIdentity(identity);
6621 }
6622 }
6623
6624 @Override
6625 public boolean setCdmaSubscriptionMode(int subId, int mode) {
6626 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6627 mApp, subId, "setCdmaSubscriptionMode");
6628
6629 final long identity = Binder.clearCallingIdentity();
6630 try {
6631 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
6632 } finally {
6633 Binder.restoreCallingIdentity(identity);
6634 }
6635 }
Makoto Onukida3bf792018-09-18 16:06:29 -07006636
6637 private void ensureUserRunning(int userId) {
6638 if (!mUserManager.isUserRunning(userId)) {
6639 throw new IllegalStateException("User " + userId + " does not exist or not running");
6640 }
6641 }
6642
6643 /**
6644 * Returns a list of SMS apps on a given user.
6645 *
6646 * Only the shell user (UID 2000 or 0) can call it.
6647 * Target user must be running.
6648 */
6649 @Override
6650 public String[] getSmsApps(int userId) {
6651 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
6652 ensureUserRunning(userId);
6653
6654 final Collection<SmsApplicationData> apps =
6655 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
6656
6657 String[] ret = new String[apps.size()];
6658 int i = 0;
6659 for (SmsApplicationData app : apps) {
6660 ret[i++] = app.mPackageName;
6661 }
6662 return ret;
6663 }
6664
6665 /**
6666 * Returns the default SMS app package name on a given user.
6667 *
6668 * Only the shell user (UID 2000 or 0) can call it.
6669 * Target user must be running.
6670 */
6671 @Override
6672 public String getDefaultSmsApp(int userId) {
6673 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
6674 ensureUserRunning(userId);
6675
6676 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
6677 /* updateIfNeeded= */ true, userId);
6678 return cn == null ? null : cn.getPackageName();
6679 }
6680
6681 /**
6682 * Set a package as the default SMS app on a given user.
6683 *
6684 * Only the shell user (UID 2000 or 0) can call it.
6685 * Target user must be running.
6686 */
6687 @Override
6688 public void setDefaultSmsApp(int userId, String packageName) {
6689 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
6690 ensureUserRunning(userId);
6691
6692 boolean found = false;
6693 for (String pkg : getSmsApps(userId)) {
6694 if (TextUtils.equals(packageName, pkg)) {
6695 found = true;
6696 break;
6697 }
6698 }
6699 if (!found) {
6700 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
6701 }
6702
6703 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
6704 }
sqianc5eccab2018-10-19 18:46:41 -07006705
6706 @Override
sqian8c685422019-02-22 15:55:18 -08006707 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
sqianc5eccab2018-10-19 18:46:41 -07006708 String callingPackage) {
sqian11b7a0e2018-12-05 18:48:28 -08006709 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
sqian8c685422019-02-22 15:55:18 -08006710 mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08006711 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6712 }
6713 final long identity = Binder.clearCallingIdentity();
6714 try {
sqian854d44b2018-12-12 16:48:18 -08006715 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
6716 for (Phone phone: PhoneFactory.getPhones()) {
6717 if (phone.getEmergencyNumberTracker() != null
6718 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
6719 emergencyNumberListInternal.put(
6720 phone.getSubId(),
6721 phone.getEmergencyNumberTracker().getEmergencyNumberList());
6722 }
sqian11b7a0e2018-12-05 18:48:28 -08006723 }
sqian854d44b2018-12-12 16:48:18 -08006724 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08006725 } finally {
6726 Binder.restoreCallingIdentity(identity);
6727 }
sqianc5eccab2018-10-19 18:46:41 -07006728 }
6729
6730 @Override
sqian8c685422019-02-22 15:55:18 -08006731 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006732 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08006733 if (!exactMatch) {
6734 TelephonyPermissions
6735 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08006736 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08006737 }
6738 final long identity = Binder.clearCallingIdentity();
6739 try {
sqian854d44b2018-12-12 16:48:18 -08006740 for (Phone phone: PhoneFactory.getPhones()) {
6741 if (phone.getEmergencyNumberTracker() != null
6742 && phone.getEmergencyNumberTracker() != null) {
6743 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
6744 number, exactMatch)) {
6745 return true;
sqian11b7a0e2018-12-05 18:48:28 -08006746 }
6747 }
sqian11b7a0e2018-12-05 18:48:28 -08006748 }
6749 return false;
6750 } finally {
6751 Binder.restoreCallingIdentity(identity);
6752 }
6753 }
6754
sqianf4ca7ed2019-01-15 18:32:07 -08006755 /**
6756 * Update emergency number list for test mode.
6757 */
6758 @Override
6759 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
6760 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6761 "updateEmergencyNumberListTestMode");
6762
6763 final long identity = Binder.clearCallingIdentity();
6764 try {
6765 for (Phone phone: PhoneFactory.getPhones()) {
6766 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6767 if (tracker != null) {
6768 tracker.executeEmergencyNumberTestModeCommand(action, num);
6769 }
6770 }
6771 } finally {
6772 Binder.restoreCallingIdentity(identity);
6773 }
6774 }
6775
6776 /**
6777 * Get the full emergency number list for test mode.
6778 */
6779 @Override
6780 public List<String> getEmergencyNumberListTestMode() {
6781 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6782 "getEmergencyNumberListTestMode");
6783
6784 final long identity = Binder.clearCallingIdentity();
6785 try {
6786 Set<String> emergencyNumbers = new HashSet<>();
6787 for (Phone phone: PhoneFactory.getPhones()) {
6788 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6789 if (tracker != null) {
6790 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
6791 emergencyNumbers.add(num.getNumber());
6792 }
6793 }
6794 }
6795 return new ArrayList<>(emergencyNumbers);
6796 } finally {
6797 Binder.restoreCallingIdentity(identity);
6798 }
6799 }
6800
chen xud6b45bd2018-10-30 22:27:10 -07006801 @Override
6802 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
6803 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
6804 Phone phone = getPhone(subId);
6805 if (phone == null) {
6806 return null;
6807 }
6808 final long identity = Binder.clearCallingIdentity();
6809 try {
6810 UiccProfile profile = UiccController.getInstance()
6811 .getUiccProfileForPhone(phone.getPhoneId());
6812 if (profile != null) {
6813 return profile.getCertsFromCarrierPrivilegeAccessRules();
6814 }
6815 } finally {
6816 Binder.restoreCallingIdentity(identity);
6817 }
6818 return null;
6819 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08006820
6821 /**
6822 * Enable or disable a modem stack.
6823 */
6824 @Override
6825 public boolean enableModemForSlot(int slotIndex, boolean enable) {
6826 enforceModifyPermission();
6827
6828 final long identity = Binder.clearCallingIdentity();
6829 try {
6830 Phone phone = PhoneFactory.getPhone(slotIndex);
6831 if (phone == null) {
6832 return false;
6833 } else {
6834 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
6835 }
6836 } finally {
6837 Binder.restoreCallingIdentity(identity);
6838 }
6839 }
Michelecea4cf22018-12-21 15:00:11 -08006840
Malcolm Chen4bcd9822019-03-27 18:34:05 -07006841 /**
6842 * Whether a modem stack is enabled or not.
6843 */
6844 @Override
6845 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage) {
6846 Phone phone = PhoneFactory.getPhone(slotIndex);
6847 if (phone == null) return false;
6848
6849 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6850 mApp, phone.getSubId(), callingPackage, "isModemEnabledForSlot")) {
6851 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6852 }
6853
6854 final long identity = Binder.clearCallingIdentity();
6855 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07006856 try {
6857 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
6858 } catch (NoSuchElementException ex) {
6859 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
6860 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07006861 } finally {
6862 Binder.restoreCallingIdentity(identity);
6863 }
6864 }
6865
Michelecea4cf22018-12-21 15:00:11 -08006866 @Override
Michele0ea7d782019-03-19 14:58:42 -07006867 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08006868 enforceModifyPermission();
6869
6870 final long identity = Binder.clearCallingIdentity();
6871 try {
6872 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07006873 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08006874 .commit();
6875 } finally {
6876 Binder.restoreCallingIdentity(identity);
6877 }
6878 }
6879
6880 @Override
Michele0ea7d782019-03-19 14:58:42 -07006881 @TelephonyManager.IsMultiSimSupportedResult
6882 public int isMultiSimSupported(String callingPackage) {
Michele4245e952019-02-04 11:36:23 -08006883 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Michele0ea7d782019-03-19 14:58:42 -07006884 getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) {
6885 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08006886 }
Michelecea4cf22018-12-21 15:00:11 -08006887
6888 final long identity = Binder.clearCallingIdentity();
6889 try {
Michele0ea7d782019-03-19 14:58:42 -07006890 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08006891 } finally {
6892 Binder.restoreCallingIdentity(identity);
6893 }
6894 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006895
Michele0ea7d782019-03-19 14:58:42 -07006896 @TelephonyManager.IsMultiSimSupportedResult
6897 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08006898 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
6899 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
6900 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07006901 loge("isMultiSimSupportedInternal: requires at least 2 cards");
6902 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006903 }
6904 // Check if the hardware supports multisim functionality. If usage of multisim is not
6905 // supported by the modem, indicate that it is restricted.
6906 PhoneCapability staticCapability =
6907 mPhoneConfigurationManager.getStaticPhoneCapability();
6908 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07006909 loge("isMultiSimSupportedInternal: no static configuration available");
6910 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006911 }
6912 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07006913 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
6914 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006915 }
6916 // Check if support of multiple SIMs is restricted by carrier
6917 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07006918 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08006919 }
6920
Michele0ea7d782019-03-19 14:58:42 -07006921 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08006922 }
6923
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006924 /**
6925 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08006926 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
6927 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
6928 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006929 * @param numOfSims number of active sims we want to switch to
6930 */
6931 @Override
6932 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08006933 if (numOfSims == 1) {
6934 enforceModifyPermission();
6935 } else {
6936 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6937 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
6938 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006939 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08006940
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006941 try {
Michele30b57b22019-03-01 12:01:14 -08006942 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07006943 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08006944 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
6945 return;
6946 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006947 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
6948 } finally {
6949 Binder.restoreCallingIdentity(identity);
6950 }
6951 }
6952
6953 /**
chen xub4baa772019-04-03 10:23:41 -07006954 * Get whether making changes to modem configurations will trigger reboot.
6955 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08006956 */
6957 @Override
chen xub4baa772019-04-03 10:23:41 -07006958 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage) {
6959 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6960 mApp, subId, callingPackage, "doesSwitchMultiSimConfigTriggerReboot")) {
6961 return false;
6962 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08006963 final long identity = Binder.clearCallingIdentity();
6964 try {
6965 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
6966 } finally {
6967 Binder.restoreCallingIdentity(identity);
6968 }
6969 }
6970
Nathan Harold29f5f052019-02-15 13:41:57 -08006971 private void updateModemStateMetrics() {
6972 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
6973 // TODO: check the state for each modem if the api is ready.
6974 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
6975 }
6976
Pengquan Meng3889a572019-01-23 11:16:29 -08006977 @Override
6978 public int[] getSlotsMapping() {
6979 enforceReadPrivilegedPermission("getSlotsMapping");
6980
6981 final long identity = Binder.clearCallingIdentity();
6982 try {
6983 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
6984 // All logical slots should have a mapping to a physical slot.
6985 int[] logicalSlotsMapping = new int[phoneCount];
6986 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
6987 for (int i = 0; i < slotInfos.length; i++) {
6988 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
6989 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
6990 }
6991 }
6992 return logicalSlotsMapping;
6993 } finally {
6994 Binder.restoreCallingIdentity(identity);
6995 }
6996 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08006997
6998 /**
6999 * Get the IRadio HAL Version
7000 */
7001 @Override
7002 public int getRadioHalVersion() {
7003 Phone phone = getDefaultPhone();
7004 if (phone == null) return -1;
7005 HalVersion hv = phone.getHalVersion();
7006 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7007 return hv.major * 100 + hv.minor;
7008 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007009
7010 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007011 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7012 * corresponding network requests on a subId.
7013 *
7014 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007015 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007016 * 2) APN is un-metered for this subscription, or
7017 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
7018 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on.
7019 *
7020 * @return whether data is allowed for a apn type.
7021 *
7022 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007023 */
7024 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007025 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007026 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Malcolm Chene5ad5792019-04-18 13:51:02 -07007027 mApp, subId, callingPackage, "isDataEnabledForApn")) {
7028 throw new SecurityException("Needs READ_PHONE_STATE for isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007029 }
7030
7031 // Now that all security checks passes, perform the operation as ourselves.
7032 final long identity = Binder.clearCallingIdentity();
7033 try {
7034 Phone phone = getPhone(subId);
7035 if (phone == null) return false;
7036
Jack Yu41407ee2019-05-13 16:54:09 -07007037 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07007038 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7039 } finally {
7040 Binder.restoreCallingIdentity(identity);
7041 }
7042 }
7043
7044 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07007045 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07007046 enforceReadPrivilegedPermission("isApnMetered");
7047
7048 // Now that all security checks passes, perform the operation as ourselves.
7049 final long identity = Binder.clearCallingIdentity();
7050 try {
7051 Phone phone = getPhone(subId);
7052 if (phone == null) return true; // By default return true.
7053
Jack Yu41407ee2019-05-13 16:54:09 -07007054 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007055 } finally {
7056 Binder.restoreCallingIdentity(identity);
7057 }
7058 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007059
7060 @Override
7061 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
7062 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
7063 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
7064 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
7065 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
7066 }
7067 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
7068 Intent intent = new Intent();
7069 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
7070 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7071 // Bring up choose default SMS subscription dialog right now
7072 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
7073 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
7074 mApp.startActivity(intent);
7075 }
chen xud5ca2d52019-05-28 15:20:57 -07007076
7077 @Override
7078 public String getMmsUAProfUrl(int subId) {
7079 //TODO investigate if this API should require proper permission check in R b/133791609
7080 final long identity = Binder.clearCallingIdentity();
7081 try {
7082 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7083 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
7084 } finally {
7085 Binder.restoreCallingIdentity(identity);
7086 }
7087 }
7088
7089 @Override
7090 public String getMmsUserAgent(int subId) {
7091 //TODO investigate if this API should require proper permission check in R b/133791609
7092 final long identity = Binder.clearCallingIdentity();
7093 try {
7094 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7095 .getString(com.android.internal.R.string.config_mms_user_agent);
7096 } finally {
7097 Binder.restoreCallingIdentity(identity);
7098 }
7099 }
Jack Yub07d4972019-05-28 16:12:25 -07007100
7101 @Override
7102 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
7103 enforceModifyPermission();
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 false;
7110
7111 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
7112 } finally {
7113 Binder.restoreCallingIdentity(identity);
7114 }
7115 }
7116
7117 @Override
7118 public boolean isDataAllowedInVoiceCall(int subId) {
7119 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
7120
7121 // Now that all security checks passes, perform the operation as ourselves.
7122 final long identity = Binder.clearCallingIdentity();
7123 try {
7124 Phone phone = getPhone(subId);
7125 if (phone == null) return false;
7126
7127 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
7128 } finally {
7129 Binder.restoreCallingIdentity(identity);
7130 }
7131 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007132}