blob: 8b5eac20c7453c6c42457469d05300d863e2a3f1 [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;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700116import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700117import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700118import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800119import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700120import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700121import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700122import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800123import com.android.internal.telephony.HalVersion;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700124import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800125import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700126import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800127import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700128import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100129import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700130import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700131import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700132import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700133import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800134import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700135import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700136import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700137import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700138import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700139import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700140import com.android.internal.telephony.ServiceStateTracker;
Makoto Onukida3bf792018-09-18 16:06:29 -0700141import com.android.internal.telephony.SmsApplication;
142import com.android.internal.telephony.SmsApplication.SmsApplicationData;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700143import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700144import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800145import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800146import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700147import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800148import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700149import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800150import com.android.internal.telephony.ims.ImsResolver;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800151import com.android.internal.telephony.metrics.TelephonyMetrics;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700152import com.android.internal.telephony.uicc.IccIoResult;
153import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800154import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700155import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800156import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700157import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800158import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000159import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700160import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800161import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700162import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700163import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800164import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700165import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700166import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800167
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700168import java.io.FileDescriptor;
169import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700170import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800171import java.util.Arrays;
Makoto Onukida3bf792018-09-18 16:06:29 -0700172import java.util.Collection;
sqian11b7a0e2018-12-05 18:48:28 -0800173import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800174import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800175import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100176import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800177import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700178import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800179import java.util.Set;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700180
181/**
182 * Implementation of the ITelephony interface.
183 */
Santos Cordon117fee72014-05-16 17:56:12 -0700184public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700185 private static final String LOG_TAG = "PhoneInterfaceManager";
186 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
187 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800188 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700189
190 // Message codes used with mMainThreadHandler
191 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700192 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
193 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700194 private static final int CMD_OPEN_CHANNEL = 9;
195 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
196 private static final int CMD_CLOSE_CHANNEL = 11;
197 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800198 private static final int CMD_NV_READ_ITEM = 13;
199 private static final int EVENT_NV_READ_ITEM_DONE = 14;
200 private static final int CMD_NV_WRITE_ITEM = 15;
201 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
202 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
203 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700204 private static final int CMD_RESET_MODEM_CONFIG = 19;
205 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800206 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
207 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
208 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
209 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800210 private static final int CMD_SEND_ENVELOPE = 25;
211 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000212 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
213 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700214 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
215 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
216 private static final int CMD_EXCHANGE_SIM_IO = 31;
217 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800218 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
219 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700220 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
221 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700222 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
223 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700224 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
225 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
226 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
227 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700228 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
229 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
230 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
231 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700232 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800233 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
234 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000235 private static final int CMD_SWITCH_SLOTS = 50;
236 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700237 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
238 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
239 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
240 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
241 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
242 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
243 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
244 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700245 private static final int CMD_GET_ALL_CELL_INFO = 60;
246 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
247 private static final int CMD_GET_CELL_LOCATION = 62;
248 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700249 private static final int CMD_MODEM_REBOOT = 64;
250 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700251 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
252 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800253 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
254 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700255 private static final int CMD_GET_MODEM_STATUS = 70;
256 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700257
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800258 // Parameters of select command.
259 private static final int SELECT_COMMAND = 0xA4;
260 private static final int SELECT_P1 = 0x04;
261 private static final int SELECT_P2 = 0;
262 private static final int SELECT_P3 = 0x10;
263
Pengquan Meng85728fb2018-03-12 16:31:21 -0700264 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
265 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
266 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
267
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700268 /** The singleton instance. */
269 private static PhoneInterfaceManager sInstance;
270
Wink Saville3ab207e2014-11-20 13:07:20 -0800271 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800272 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700273 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800274 private AppOpsManager mAppOps;
275 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800276 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800277 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700278 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700279
Derek Tan97ebb422014-09-05 16:55:38 -0700280 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
281 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800282 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800283 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700284
Michelecea4cf22018-12-21 15:00:11 -0800285 // String to store multi SIM allowed
286 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
287
Derek Tan740e1672017-06-27 14:56:27 -0700288 // The AID of ISD-R.
289 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
290
yinxub1bed742017-04-17 11:45:04 -0700291 private NetworkScanRequestTracker mNetworkScanRequestTracker;
292
David Kelly5e06a7f2018-03-12 14:10:59 +0000293 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
294 private static final int MANUFACTURER_CODE_LENGTH = 8;
295
Derek Tan89e89d42014-07-08 17:00:10 -0700296 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700297 * A request object to use for transmitting data to an ICC.
298 */
299 private static final class IccAPDUArgument {
300 public int channel, cla, command, p1, p2, p3;
301 public String data;
302
303 public IccAPDUArgument(int channel, int cla, int command,
304 int p1, int p2, int p3, String data) {
305 this.channel = channel;
306 this.cla = cla;
307 this.command = command;
308 this.p1 = p1;
309 this.p2 = p2;
310 this.p3 = p3;
311 this.data = data;
312 }
313 }
314
315 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700316 * A request object to use for transmitting data to an ICC.
317 */
318 private static final class ManualNetworkSelectionArgument {
319 public OperatorInfo operatorInfo;
320 public boolean persistSelection;
321
322 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
323 this.operatorInfo = operatorInfo;
324 this.persistSelection = persistSelection;
325 }
326 }
327
328 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700329 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
330 * request after sending. The main thread will notify the request when it is complete.
331 */
332 private static final class MainThreadRequest {
333 /** The argument to use for the request */
334 public Object argument;
335 /** The result of the request that is run on the main thread */
336 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800337 // The subscriber id that this request applies to. Defaults to
338 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
339 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700340
Nathan Harold92bed182018-10-12 18:16:49 -0700341 // In cases where subId is unavailable, the caller needs to specify the phone.
342 public Phone phone;
343
vagdeviaf9a5b92018-08-15 16:01:53 -0700344 public WorkSource workSource;
345
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700346 public MainThreadRequest(Object argument) {
347 this.argument = argument;
348 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800349
Nathan Harold92bed182018-10-12 18:16:49 -0700350 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
351 this.argument = argument;
352 if (phone != null) {
353 this.phone = phone;
354 }
355 this.workSource = workSource;
356 }
357
vagdeviaf9a5b92018-08-15 16:01:53 -0700358 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800359 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800360 if (subId != null) {
361 this.subId = subId;
362 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700363 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800364 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700365 }
366
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800367 private static final class IncomingThirdPartyCallArgs {
368 public final ComponentName component;
369 public final String callId;
370 public final String callerDisplayName;
371
372 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
373 String callerDisplayName) {
374 this.component = component;
375 this.callId = callId;
376 this.callerDisplayName = callerDisplayName;
377 }
378 }
379
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700380 /**
381 * A handler that processes messages on the main thread in the phone process. Since many
382 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
383 * inbound binder threads to the main thread in the phone process. The Binder thread
384 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
385 * on, which will be notified when the operation completes and will contain the result of the
386 * request.
387 *
388 * <p>If a MainThreadRequest object is provided in the msg.obj field,
389 * note that request.result must be set to something non-null for the calling thread to
390 * unblock.
391 */
392 private final class MainThreadHandler extends Handler {
393 @Override
394 public void handleMessage(Message msg) {
395 MainThreadRequest request;
396 Message onCompleted;
397 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800398 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700399 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800400 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700401
402 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700403 case CMD_HANDLE_USSD_REQUEST: {
404 request = (MainThreadRequest) msg.obj;
405 final Phone phone = getPhoneFromRequest(request);
406 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
407 String ussdRequest = ussdObject.first;
408 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700409
Pengquan Menga1bb6272018-09-06 09:59:22 -0700410 if (!isUssdApiAllowed(request.subId)) {
411 // Carrier does not support use of this API, return failure.
412 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
413 UssdResponse response = new UssdResponse(ussdRequest, null);
414 Bundle returnData = new Bundle();
415 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
416 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700417
Pengquan Menga1bb6272018-09-06 09:59:22 -0700418 request.result = true;
419 notifyRequester(request);
420 return;
421 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700422
Pengquan Menga1bb6272018-09-06 09:59:22 -0700423 try {
424 request.result = phone != null
425 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
426 } catch (CallStateException cse) {
427 request.result = false;
428 }
429 // Wake up the requesting thread
430 notifyRequester(request);
431 break;
pkanwar32d516d2016-10-14 19:37:38 -0700432 }
433
Yorke Lee716f67e2015-06-17 15:39:16 -0700434 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700435 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700436 final Phone phone = getPhoneFromRequest(request);
437 request.result = phone != null ?
438 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
439 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700440 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700441 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700442 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700443 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700444
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700445 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700446 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700447 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800448 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700449 if (uiccCard == null) {
450 loge("iccTransmitApduLogicalChannel: No UICC");
451 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700452 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700453 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700454 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
455 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700456 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700457 iccArgument.channel, iccArgument.cla, iccArgument.command,
458 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700459 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700460 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700461 break;
462
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700463 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700464 ar = (AsyncResult) msg.obj;
465 request = (MainThreadRequest) ar.userObj;
466 if (ar.exception == null && ar.result != null) {
467 request.result = ar.result;
468 } else {
469 request.result = new IccIoResult(0x6F, 0, (byte[])null);
470 if (ar.result == null) {
471 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800472 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700473 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800474 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700475 } else {
476 loge("iccTransmitApduLogicalChannel: Unknown exception");
477 }
478 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700479 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700480 break;
481
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700482 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
483 request = (MainThreadRequest) msg.obj;
484 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800485 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700486 if (uiccCard == null) {
487 loge("iccTransmitApduBasicChannel: No UICC");
488 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700489 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700490 } else {
491 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
492 request);
493 uiccCard.iccTransmitApduBasicChannel(
494 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
495 iccArgument.p3, iccArgument.data, onCompleted);
496 }
497 break;
498
499 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
500 ar = (AsyncResult) msg.obj;
501 request = (MainThreadRequest) ar.userObj;
502 if (ar.exception == null && ar.result != null) {
503 request.result = ar.result;
504 } else {
505 request.result = new IccIoResult(0x6F, 0, (byte[])null);
506 if (ar.result == null) {
507 loge("iccTransmitApduBasicChannel: Empty response");
508 } else if (ar.exception instanceof CommandException) {
509 loge("iccTransmitApduBasicChannel: CommandException: " +
510 ar.exception);
511 } else {
512 loge("iccTransmitApduBasicChannel: Unknown exception");
513 }
514 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700515 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700516 break;
517
518 case CMD_EXCHANGE_SIM_IO:
519 request = (MainThreadRequest) msg.obj;
520 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800521 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700522 if (uiccCard == null) {
523 loge("iccExchangeSimIO: No UICC");
524 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700525 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700526 } else {
527 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
528 request);
529 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
530 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
531 iccArgument.data, onCompleted);
532 }
533 break;
534
535 case EVENT_EXCHANGE_SIM_IO_DONE:
536 ar = (AsyncResult) msg.obj;
537 request = (MainThreadRequest) ar.userObj;
538 if (ar.exception == null && ar.result != null) {
539 request.result = ar.result;
540 } else {
541 request.result = new IccIoResult(0x6f, 0, (byte[])null);
542 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700543 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700544 break;
545
Derek Tan4d5e5c12014-02-04 11:54:58 -0800546 case CMD_SEND_ENVELOPE:
547 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800548 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700549 if (uiccCard == null) {
550 loge("sendEnvelopeWithStatus: No UICC");
551 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700552 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700553 } else {
554 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
555 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
556 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800557 break;
558
559 case EVENT_SEND_ENVELOPE_DONE:
560 ar = (AsyncResult) msg.obj;
561 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700562 if (ar.exception == null && ar.result != null) {
563 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800564 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700565 request.result = new IccIoResult(0x6F, 0, (byte[])null);
566 if (ar.result == null) {
567 loge("sendEnvelopeWithStatus: Empty response");
568 } else if (ar.exception instanceof CommandException) {
569 loge("sendEnvelopeWithStatus: CommandException: " +
570 ar.exception);
571 } else {
572 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
573 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800574 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700575 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800576 break;
577
Shishir Agrawal566b7612013-10-28 14:41:00 -0700578 case CMD_OPEN_CHANNEL:
579 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800580 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800581 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700582 if (uiccCard == null) {
583 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800584 request.result = new IccOpenLogicalChannelResponse(-1,
585 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700586 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700587 } else {
588 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800589 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
590 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700591 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700592 break;
593
594 case EVENT_OPEN_CHANNEL_DONE:
595 ar = (AsyncResult) msg.obj;
596 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700597 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700598 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700599 int[] result = (int[]) ar.result;
600 int channelId = result[0];
601 byte[] selectResponse = null;
602 if (result.length > 1) {
603 selectResponse = new byte[result.length - 1];
604 for (int i = 1; i < result.length; ++i) {
605 selectResponse[i - 1] = (byte) result[i];
606 }
607 }
608 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700609 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700610 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700611 if (ar.result == null) {
612 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700613 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700614 if (ar.exception != null) {
615 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
616 }
617
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700618 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700619 if (ar.exception instanceof CommandException) {
620 CommandException.Error error =
621 ((CommandException) (ar.exception)).getCommandError();
622 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700623 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700624 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700625 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700626 }
627 }
628 openChannelResp = new IccOpenLogicalChannelResponse(
629 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700630 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700631 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700632 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700633 break;
634
635 case CMD_CLOSE_CHANNEL:
636 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800637 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700638 if (uiccCard == null) {
639 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900640 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700641 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700642 } else {
643 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
644 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
645 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700646 break;
647
648 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800649 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
650 break;
651
652 case CMD_NV_READ_ITEM:
653 request = (MainThreadRequest) msg.obj;
654 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800655 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
656 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800657 break;
658
659 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700660 ar = (AsyncResult) msg.obj;
661 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800662 if (ar.exception == null && ar.result != null) {
663 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700664 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800665 request.result = "";
666 if (ar.result == null) {
667 loge("nvReadItem: Empty response");
668 } else if (ar.exception instanceof CommandException) {
669 loge("nvReadItem: CommandException: " +
670 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700671 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800672 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700673 }
674 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700675 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700676 break;
677
Jake Hambye994d462014-02-03 13:10:13 -0800678 case CMD_NV_WRITE_ITEM:
679 request = (MainThreadRequest) msg.obj;
680 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
681 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800682 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700683 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800684 break;
685
686 case EVENT_NV_WRITE_ITEM_DONE:
687 handleNullReturnEvent(msg, "nvWriteItem");
688 break;
689
690 case CMD_NV_WRITE_CDMA_PRL:
691 request = (MainThreadRequest) msg.obj;
692 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800693 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800694 break;
695
696 case EVENT_NV_WRITE_CDMA_PRL_DONE:
697 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
698 break;
699
chen xu6dac5ab2018-10-26 17:39:23 -0700700 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800701 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700702 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800703 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800704 break;
705
chen xu6dac5ab2018-10-26 17:39:23 -0700706 case EVENT_RESET_MODEM_CONFIG_DONE:
707 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800708 break;
709
Jake Hamby7c27be32014-03-03 13:25:59 -0800710 case CMD_GET_PREFERRED_NETWORK_TYPE:
711 request = (MainThreadRequest) msg.obj;
712 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700713 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800714 break;
715
716 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
717 ar = (AsyncResult) msg.obj;
718 request = (MainThreadRequest) ar.userObj;
719 if (ar.exception == null && ar.result != null) {
720 request.result = ar.result; // Integer
721 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800722 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800723 if (ar.result == null) {
724 loge("getPreferredNetworkType: Empty response");
725 } else if (ar.exception instanceof CommandException) {
726 loge("getPreferredNetworkType: CommandException: " +
727 ar.exception);
728 } else {
729 loge("getPreferredNetworkType: Unknown exception");
730 }
731 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700732 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800733 break;
734
735 case CMD_SET_PREFERRED_NETWORK_TYPE:
736 request = (MainThreadRequest) msg.obj;
737 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
738 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700739 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800740 break;
741
742 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
743 handleNullReturnEvent(msg, "setPreferredNetworkType");
744 break;
745
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000746 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
747 request = (MainThreadRequest)msg.obj;
748 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800749 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000750 break;
751
752 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
753 ar = (AsyncResult)msg.obj;
754 request = (MainThreadRequest)ar.userObj;
755 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700756 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000757 break;
758
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800759 case CMD_SET_VOICEMAIL_NUMBER:
760 request = (MainThreadRequest) msg.obj;
761 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
762 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800763 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
764 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800765 break;
766
767 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
768 handleNullReturnEvent(msg, "setVoicemailNumber");
769 break;
770
Stuart Scott54788802015-03-30 13:18:01 -0700771 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
772 request = (MainThreadRequest) msg.obj;
773 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
774 request);
775 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
776 break;
777
778 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
779 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
780 break;
781
Shishir Agrawal302c8692015-06-19 13:49:39 -0700782 case CMD_PERFORM_NETWORK_SCAN:
783 request = (MainThreadRequest) msg.obj;
784 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
785 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
786 break;
787
788 case EVENT_PERFORM_NETWORK_SCAN_DONE:
789 ar = (AsyncResult) msg.obj;
790 request = (MainThreadRequest) ar.userObj;
791 CellNetworkScanResult cellScanResult;
792 if (ar.exception == null && ar.result != null) {
793 cellScanResult = new CellNetworkScanResult(
794 CellNetworkScanResult.STATUS_SUCCESS,
795 (List<OperatorInfo>) ar.result);
796 } else {
797 if (ar.result == null) {
798 loge("getCellNetworkScanResults: Empty response");
799 }
800 if (ar.exception != null) {
801 loge("getCellNetworkScanResults: Exception: " + ar.exception);
802 }
803 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
804 if (ar.exception instanceof CommandException) {
805 CommandException.Error error =
806 ((CommandException) (ar.exception)).getCommandError();
807 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
808 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
809 } else if (error == CommandException.Error.GENERIC_FAILURE) {
810 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
811 }
812 }
813 cellScanResult = new CellNetworkScanResult(errorCode, null);
814 }
815 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700816 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700817 break;
818
819 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
820 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700821 ManualNetworkSelectionArgument selArg =
822 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700823 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
824 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700825 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
826 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700827 break;
828
829 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700830 ar = (AsyncResult) msg.obj;
831 request = (MainThreadRequest) ar.userObj;
832 if (ar.exception == null) {
833 request.result = true;
834 } else {
835 request.result = false;
836 loge("setNetworkSelectionModeManual " + ar.exception);
837 }
838 notifyRequester(request);
839 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700840 break;
841
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700842 case CMD_GET_MODEM_ACTIVITY_INFO:
843 request = (MainThreadRequest) msg.obj;
844 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -0700845 if (defaultPhone != null) {
846 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
847 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700848 break;
849
850 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
851 ar = (AsyncResult) msg.obj;
852 request = (MainThreadRequest) ar.userObj;
853 if (ar.exception == null && ar.result != null) {
854 request.result = ar.result;
855 } else {
856 if (ar.result == null) {
857 loge("queryModemActivityInfo: Empty response");
858 } else if (ar.exception instanceof CommandException) {
859 loge("queryModemActivityInfo: CommandException: " +
860 ar.exception);
861 } else {
862 loge("queryModemActivityInfo: Unknown exception");
863 }
864 }
Amit Mahajand4766222016-01-28 15:28:28 -0800865 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
866 if (request.result == null) {
867 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
868 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700869 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700870 break;
871
Meng Wang1a7c35a2016-05-05 20:56:15 -0700872 case CMD_SET_ALLOWED_CARRIERS:
873 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -0800874 CarrierRestrictionRules argument =
875 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700876 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -0800877 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700878 break;
879
880 case EVENT_SET_ALLOWED_CARRIERS_DONE:
881 ar = (AsyncResult) msg.obj;
882 request = (MainThreadRequest) ar.userObj;
883 if (ar.exception == null && ar.result != null) {
884 request.result = ar.result;
885 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800886 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
887 if (ar.exception instanceof CommandException) {
888 loge("setAllowedCarriers: CommandException: " + ar.exception);
889 CommandException.Error error =
890 ((CommandException) (ar.exception)).getCommandError();
891 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
892 request.result =
893 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
894 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700895 } else {
896 loge("setAllowedCarriers: Unknown exception");
897 }
898 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700899 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700900 break;
901
902 case CMD_GET_ALLOWED_CARRIERS:
903 request = (MainThreadRequest) msg.obj;
904 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800905 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700906 break;
907
908 case EVENT_GET_ALLOWED_CARRIERS_DONE:
909 ar = (AsyncResult) msg.obj;
910 request = (MainThreadRequest) ar.userObj;
911 if (ar.exception == null && ar.result != null) {
912 request.result = ar.result;
913 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800914 request.result = new IllegalStateException(
915 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700916 if (ar.result == null) {
917 loge("getAllowedCarriers: Empty response");
918 } else if (ar.exception instanceof CommandException) {
919 loge("getAllowedCarriers: CommandException: " +
920 ar.exception);
921 } else {
922 loge("getAllowedCarriers: Unknown exception");
923 }
924 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700925 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700926 break;
927
Nathan Haroldb3014052017-01-25 15:57:32 -0800928 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
929 ar = (AsyncResult) msg.obj;
930 request = (MainThreadRequest) ar.userObj;
931 if (ar.exception == null && ar.result != null) {
932 request.result = ar.result;
933 } else {
934 request.result = new IllegalArgumentException(
935 "Failed to retrieve Forbidden Plmns");
936 if (ar.result == null) {
937 loge("getForbiddenPlmns: Empty response");
938 } else {
939 loge("getForbiddenPlmns: Unknown exception");
940 }
941 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700942 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800943 break;
944
945 case CMD_GET_FORBIDDEN_PLMNS:
946 request = (MainThreadRequest) msg.obj;
947 uiccCard = getUiccCardFromRequest(request);
948 if (uiccCard == null) {
949 loge("getForbiddenPlmns() UiccCard is null");
950 request.result = new IllegalArgumentException(
951 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700952 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800953 break;
954 }
955 Integer appType = (Integer) request.argument;
956 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
957 if (uiccApp == null) {
958 loge("getForbiddenPlmns() no app with specified type -- "
959 + appType);
960 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700961 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800962 break;
963 } else {
964 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
965 + " specified type -- " + appType);
966 }
967 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
968 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
969 onCompleted);
970 break;
971
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000972 case CMD_SWITCH_SLOTS:
973 request = (MainThreadRequest) msg.obj;
974 int[] physicalSlots = (int[]) request.argument;
975 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
976 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
977 break;
978
979 case EVENT_SWITCH_SLOTS_DONE:
980 ar = (AsyncResult) msg.obj;
981 request = (MainThreadRequest) ar.userObj;
982 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700983 notifyRequester(request);
984 break;
985 case CMD_GET_NETWORK_SELECTION_MODE:
986 request = (MainThreadRequest) msg.obj;
987 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
988 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
989 break;
990
991 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
992 ar = (AsyncResult) msg.obj;
993 request = (MainThreadRequest) ar.userObj;
994 if (ar.exception != null) {
995 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
996 } else {
997 int mode = ((int[]) ar.result)[0];
998 if (mode == 0) {
999 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1000 } else {
1001 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1002 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001003 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001004 notifyRequester(request);
1005 break;
1006 case CMD_GET_CDMA_ROAMING_MODE:
1007 request = (MainThreadRequest) msg.obj;
1008 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1009 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1010 break;
1011 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1012 ar = (AsyncResult) msg.obj;
1013 request = (MainThreadRequest) ar.userObj;
1014 if (ar.exception != null) {
1015 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1016 } else {
1017 request.result = ((int[]) ar.result)[0];
1018 }
1019 notifyRequester(request);
1020 break;
1021 case CMD_SET_CDMA_ROAMING_MODE:
1022 request = (MainThreadRequest) msg.obj;
1023 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1024 int mode = (int) request.argument;
1025 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1026 break;
1027 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1028 ar = (AsyncResult) msg.obj;
1029 request = (MainThreadRequest) ar.userObj;
1030 request.result = ar.exception == null;
1031 notifyRequester(request);
1032 break;
1033 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1034 request = (MainThreadRequest) msg.obj;
1035 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1036 int subscriptionMode = (int) request.argument;
1037 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1038 break;
1039 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1040 ar = (AsyncResult) msg.obj;
1041 request = (MainThreadRequest) ar.userObj;
1042 request.result = ar.exception == null;
1043 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001044 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001045 case CMD_GET_ALL_CELL_INFO:
1046 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001047 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001048 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001049 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001050 case EVENT_GET_ALL_CELL_INFO_DONE:
1051 ar = (AsyncResult) msg.obj;
1052 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001053 // If a timeout occurs, the response will be null
1054 request.result = (ar.exception == null && ar.result != null)
1055 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001056 synchronized (request) {
1057 request.notifyAll();
1058 }
1059 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001060 case CMD_REQUEST_CELL_INFO_UPDATE:
1061 request = (MainThreadRequest) msg.obj;
1062 request.phone.requestCellInfoUpdate(request.workSource,
1063 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1064 break;
1065 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1066 ar = (AsyncResult) msg.obj;
1067 request = (MainThreadRequest) ar.userObj;
1068 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1069 try {
1070 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001071 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Nathan Harolde82c4b82018-12-18 19:40:37 -08001072 cb.onError(TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1073 new android.os.ParcelableException(ar.exception));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001074 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001075 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Nathan Harolde82c4b82018-12-18 19:40:37 -08001076 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001077 } else {
1078 // use the result as returned
1079 cb.onCellInfo((List<CellInfo>) ar.result);
1080 }
1081 } catch (RemoteException re) {
1082 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1083 }
1084 break;
1085 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001086 request = (MainThreadRequest) msg.obj;
1087 WorkSource ws = (WorkSource) request.argument;
1088 Phone phone = getPhoneFromRequest(request);
1089 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1090 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001091 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001092 ar = (AsyncResult) msg.obj;
1093 request = (MainThreadRequest) ar.userObj;
1094 if (ar.exception == null) {
1095 request.result = ar.result;
1096 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001097 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001098 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1099 ? new CdmaCellLocation() : new GsmCellLocation();
1100 }
1101
1102 synchronized (request) {
1103 request.notifyAll();
1104 }
1105 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001106 case CMD_MODEM_REBOOT:
1107 request = (MainThreadRequest) msg.obj;
1108 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001109 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001110 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001111 case EVENT_CMD_MODEM_REBOOT_DONE:
1112 handleNullReturnEvent(msg, "rebootModem");
1113 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001114 case CMD_REQUEST_ENABLE_MODEM:
1115 request = (MainThreadRequest) msg.obj;
1116 boolean enable = (boolean) request.argument;
1117 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001118 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001119 PhoneConfigurationManager.getInstance()
1120 .enablePhone(request.phone, enable, onCompleted);
1121 break;
1122 case EVENT_ENABLE_MODEM_DONE:
1123 ar = (AsyncResult) msg.obj;
1124 request = (MainThreadRequest) ar.userObj;
1125 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001126 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001127 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001128 if ((boolean) request.result) {
1129 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1130 updateModemStateMetrics();
1131 } else {
1132 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1133 + ar.exception);
1134 }
1135 notifyRequester(request);
1136 break;
1137 case CMD_GET_MODEM_STATUS:
1138 request = (MainThreadRequest) msg.obj;
1139 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1140 PhoneConfigurationManager.getInstance()
1141 .getPhoneStatusFromModem(request.phone, onCompleted);
1142 break;
1143 case EVENT_GET_MODEM_STATUS_DONE:
1144 ar = (AsyncResult) msg.obj;
1145 request = (MainThreadRequest) ar.userObj;
1146 int id = request.phone.getPhoneId();
1147 if (ar.exception == null && ar.result != null) {
1148 request.result = ar.result;
1149 //update the cache as modem status has changed
1150 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1151 (boolean) request.result);
1152 } else {
1153 // Return true if modem status cannot be retrieved. For most cases,
1154 // modem status is on. And for older version modems, GET_MODEM_STATUS
1155 // and disable modem are not supported. Modem is always on.
1156 // TODO: this should be fixed in R to support a third
1157 // status UNKNOWN b/131631629
1158 request.result = true;
1159 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1160 + ar.exception);
1161 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001162 notifyRequester(request);
1163 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001164 default:
1165 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1166 break;
1167 }
1168 }
Jake Hambye994d462014-02-03 13:10:13 -08001169
Pengquan Menga1bb6272018-09-06 09:59:22 -07001170 private void notifyRequester(MainThreadRequest request) {
1171 synchronized (request) {
1172 request.notifyAll();
1173 }
1174 }
1175
Jake Hambye994d462014-02-03 13:10:13 -08001176 private void handleNullReturnEvent(Message msg, String command) {
1177 AsyncResult ar = (AsyncResult) msg.obj;
1178 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1179 if (ar.exception == null) {
1180 request.result = true;
1181 } else {
1182 request.result = false;
1183 if (ar.exception instanceof CommandException) {
1184 loge(command + ": CommandException: " + ar.exception);
1185 } else {
1186 loge(command + ": Unknown exception");
1187 }
1188 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001189 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001190 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001191 }
1192
1193 /**
1194 * Posts the specified command to be executed on the main thread,
1195 * waits for the request to complete, and returns the result.
1196 * @see #sendRequestAsync
1197 */
1198 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001199 return sendRequest(
1200 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001201 }
1202
1203 /**
1204 * Posts the specified command to be executed on the main thread,
1205 * waits for the request to complete, and returns the result.
1206 * @see #sendRequestAsync
1207 */
1208 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1209 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001210 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001211 }
1212
1213 /**
1214 * Posts the specified command to be executed on the main thread,
1215 * waits for the request to complete, and returns the result.
1216 * @see #sendRequestAsync
1217 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001218 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001219 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001220 }
1221
1222 /**
1223 * Posts the specified command to be executed on the main thread,
1224 * waits for the request to complete, and returns the result.
1225 * @see #sendRequestAsync
1226 */
Nathan Harold92bed182018-10-12 18:16:49 -07001227 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1228 return sendRequest(command, argument, subId, null, workSource);
1229 }
1230
1231 /**
1232 * Posts the specified command to be executed on the main thread,
1233 * waits for the request to complete, and returns the result.
1234 * @see #sendRequestAsync
1235 */
1236 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1237 return sendRequest(
1238 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1239 }
1240
1241 /**
1242 * Posts the specified command to be executed on the main thread,
1243 * waits for the request to complete, and returns the result.
1244 * @see #sendRequestAsync
1245 */
1246 private Object sendRequest(
1247 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001248 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1249 throw new RuntimeException("This method will deadlock if called from the main thread.");
1250 }
1251
Nathan Harold92bed182018-10-12 18:16:49 -07001252 MainThreadRequest request = null;
1253 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1254 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1255 } else if (phone != null) {
1256 request = new MainThreadRequest(argument, phone, workSource);
1257 } else {
1258 request = new MainThreadRequest(argument, subId, workSource);
1259 }
1260
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001261 Message msg = mMainThreadHandler.obtainMessage(command, request);
1262 msg.sendToTarget();
1263
1264 // Wait for the request to complete
1265 synchronized (request) {
1266 while (request.result == null) {
1267 try {
1268 request.wait();
1269 } catch (InterruptedException e) {
1270 // Do nothing, go back and wait until the request is complete
1271 }
1272 }
1273 }
1274 return request.result;
1275 }
1276
1277 /**
1278 * Asynchronous ("fire and forget") version of sendRequest():
1279 * Posts the specified command to be executed on the main thread, and
1280 * returns immediately.
1281 * @see #sendRequest
1282 */
1283 private void sendRequestAsync(int command) {
1284 mMainThreadHandler.sendEmptyMessage(command);
1285 }
1286
1287 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001288 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001289 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001290 */
1291 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001292 sendRequestAsync(command, argument, null, null);
1293 }
1294
1295 /**
1296 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1297 * @see {@link #sendRequest(int,Object)}
1298 */
1299 private void sendRequestAsync(
1300 int command, Object argument, Phone phone, WorkSource workSource) {
1301 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001302 Message msg = mMainThreadHandler.obtainMessage(command, request);
1303 msg.sendToTarget();
1304 }
1305
1306 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001307 * Initialize the singleton PhoneInterfaceManager instance.
1308 * This is only done once, at startup, from PhoneApp.onCreate().
1309 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001310 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001311 synchronized (PhoneInterfaceManager.class) {
1312 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001313 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001314 } else {
1315 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1316 }
1317 return sInstance;
1318 }
1319 }
1320
1321 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001322 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001323 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001324 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001325 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001326 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1327 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001328 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001329 mTelephonySharedPreferences =
1330 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001331 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001332 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001333
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001334 publish();
1335 }
1336
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001337 private Phone getDefaultPhone() {
1338 Phone thePhone = getPhone(getDefaultSubscription());
1339 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1340 }
1341
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001342 private void publish() {
1343 if (DBG) log("publish: " + this);
1344
1345 ServiceManager.addService("phone", this);
1346 }
1347
Stuart Scott584921c2015-01-15 17:10:34 -08001348 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001349 if (request.phone != null) {
1350 return request.phone;
1351 } else {
1352 return getPhoneFromSubId(request.subId);
1353 }
1354 }
1355
1356 private Phone getPhoneFromSubId(int subId) {
1357 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1358 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001359 }
1360
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001361 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1362 Phone phone = getPhoneFromRequest(request);
1363 return phone == null ? null :
1364 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1365 }
1366
Wink Saville36469e72014-06-11 15:17:00 -07001367 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001368 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001369 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001370 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001371
1372 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001373 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001374 }
1375
Wink Savilleb564aae2014-10-23 10:18:09 -07001376 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001377 if (DBG) log("dial: " + number);
1378 // No permission check needed here: This is just a wrapper around the
1379 // ACTION_DIAL intent, which is available to any app since it puts up
1380 // the UI before it does anything.
1381
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001382 final long identity = Binder.clearCallingIdentity();
1383 try {
1384 String url = createTelUrl(number);
1385 if (url == null) {
1386 return;
1387 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001388
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001389 // PENDING: should we just silently fail if phone is offhook or ringing?
1390 PhoneConstants.State state = mCM.getState(subId);
1391 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1392 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1393 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1394 mApp.startActivity(intent);
1395 }
1396 } finally {
1397 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001398 }
1399 }
1400
1401 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001402 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001403 }
1404
Wink Savilleb564aae2014-10-23 10:18:09 -07001405 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001406 if (DBG) log("call: " + number);
1407
1408 // This is just a wrapper around the ACTION_CALL intent, but we still
1409 // need to do a permission check since we're calling startActivity()
1410 // from the context of the phone app.
1411 enforceCallPermission();
1412
1413 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1414 != AppOpsManager.MODE_ALLOWED) {
1415 return;
1416 }
1417
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001418 final long identity = Binder.clearCallingIdentity();
1419 try {
1420 String url = createTelUrl(number);
1421 if (url == null) {
1422 return;
1423 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001424
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001425 boolean isValid = false;
1426 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1427 if (slist != null) {
1428 for (SubscriptionInfo subInfoRecord : slist) {
1429 if (subInfoRecord.getSubscriptionId() == subId) {
1430 isValid = true;
1431 break;
1432 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001433 }
Wink Saville08874612014-08-31 19:19:58 -07001434 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001435 if (!isValid) {
1436 return;
1437 }
Wink Saville08874612014-08-31 19:19:58 -07001438
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001439 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1440 intent.putExtra(SUBSCRIPTION_KEY, subId);
1441 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1442 mApp.startActivity(intent);
1443 } finally {
1444 Binder.restoreCallingIdentity(identity);
1445 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001446 }
1447
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001448 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001449 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001450 }
1451
Wink Savilleb564aae2014-10-23 10:18:09 -07001452 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001453 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001454 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1455 }
1456
1457 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001458 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001459 }
1460
Wink Savilleb564aae2014-10-23 10:18:09 -07001461 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001462 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001463 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1464 }
1465
1466 /** {@hide} */
1467 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001468 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001469 }
1470
Wink Savilleb564aae2014-10-23 10:18:09 -07001471 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001472 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001473
1474 final long identity = Binder.clearCallingIdentity();
1475 try {
1476 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1477 checkSimPin.start();
1478 return checkSimPin.unlockSim(null, pin);
1479 } finally {
1480 Binder.restoreCallingIdentity(identity);
1481 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001482 }
1483
Wink Saville9de0f752013-10-22 19:04:03 -07001484 /** {@hide} */
1485 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001486 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001487 }
1488
Wink Savilleb564aae2014-10-23 10:18:09 -07001489 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001490 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001491
1492 final long identity = Binder.clearCallingIdentity();
1493 try {
1494 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1495 checkSimPuk.start();
1496 return checkSimPuk.unlockSim(puk, pin);
1497 } finally {
1498 Binder.restoreCallingIdentity(identity);
1499 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001500 }
1501
1502 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001503 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001504 * a synchronous one.
1505 */
1506 private static class UnlockSim extends Thread {
1507
1508 private final IccCard mSimCard;
1509
1510 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001511 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1512 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001513
1514 // For replies from SimCard interface
1515 private Handler mHandler;
1516
1517 // For async handler to identify request type
1518 private static final int SUPPLY_PIN_COMPLETE = 100;
1519
1520 public UnlockSim(IccCard simCard) {
1521 mSimCard = simCard;
1522 }
1523
1524 @Override
1525 public void run() {
1526 Looper.prepare();
1527 synchronized (UnlockSim.this) {
1528 mHandler = new Handler() {
1529 @Override
1530 public void handleMessage(Message msg) {
1531 AsyncResult ar = (AsyncResult) msg.obj;
1532 switch (msg.what) {
1533 case SUPPLY_PIN_COMPLETE:
1534 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1535 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001536 mRetryCount = msg.arg1;
1537 if (ar.exception != null) {
1538 if (ar.exception instanceof CommandException &&
1539 ((CommandException)(ar.exception)).getCommandError()
1540 == CommandException.Error.PASSWORD_INCORRECT) {
1541 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1542 } else {
1543 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1544 }
1545 } else {
1546 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1547 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001548 mDone = true;
1549 UnlockSim.this.notifyAll();
1550 }
1551 break;
1552 }
1553 }
1554 };
1555 UnlockSim.this.notifyAll();
1556 }
1557 Looper.loop();
1558 }
1559
1560 /*
1561 * Use PIN or PUK to unlock SIM card
1562 *
1563 * If PUK is null, unlock SIM card with PIN
1564 *
1565 * If PUK is not null, unlock SIM card with PUK and set PIN code
1566 */
Wink Saville9de0f752013-10-22 19:04:03 -07001567 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001568
1569 while (mHandler == null) {
1570 try {
1571 wait();
1572 } catch (InterruptedException e) {
1573 Thread.currentThread().interrupt();
1574 }
1575 }
1576 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1577
1578 if (puk == null) {
1579 mSimCard.supplyPin(pin, callback);
1580 } else {
1581 mSimCard.supplyPuk(puk, pin, callback);
1582 }
1583
1584 while (!mDone) {
1585 try {
1586 Log.d(LOG_TAG, "wait for done");
1587 wait();
1588 } catch (InterruptedException e) {
1589 // Restore the interrupted status
1590 Thread.currentThread().interrupt();
1591 }
1592 }
1593 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001594 int[] resultArray = new int[2];
1595 resultArray[0] = mResult;
1596 resultArray[1] = mRetryCount;
1597 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001598 }
1599 }
1600
1601 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001602 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001603
1604 }
1605
Wink Savilleb564aae2014-10-23 10:18:09 -07001606 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001607 // No permission check needed here: this call is harmless, and it's
1608 // needed for the ServiceState.requestStateUpdate() call (which is
1609 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001610 final long identity = Binder.clearCallingIdentity();
1611 try {
1612 final Phone phone = getPhone(subId);
1613 if (phone != null) {
1614 phone.updateServiceLocation();
1615 }
1616 } finally {
1617 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001618 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001619 }
1620
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001621 @Override
1622 public boolean isRadioOn(String callingPackage) {
1623 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001624 }
1625
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001626 @Override
1627 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001628 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001629 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001630 return false;
1631 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001632
1633 final long identity = Binder.clearCallingIdentity();
1634 try {
1635 return isRadioOnForSubscriber(subId);
1636 } finally {
1637 Binder.restoreCallingIdentity(identity);
1638 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001639 }
1640
1641 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001642 final long identity = Binder.clearCallingIdentity();
1643 try {
1644 final Phone phone = getPhone(subId);
1645 if (phone != null) {
1646 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1647 } else {
1648 return false;
1649 }
1650 } finally {
1651 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001652 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001653 }
1654
1655 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001656 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001657 }
Wink Saville36469e72014-06-11 15:17:00 -07001658
Wink Savilleb564aae2014-10-23 10:18:09 -07001659 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001660 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001661
1662 final long identity = Binder.clearCallingIdentity();
1663 try {
1664 final Phone phone = getPhone(subId);
1665 if (phone != null) {
1666 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1667 }
1668 } finally {
1669 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001670 }
Wink Saville36469e72014-06-11 15:17:00 -07001671 }
1672
1673 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001674 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001675 }
1676
Wink Savilleb564aae2014-10-23 10:18:09 -07001677 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001678 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001679
1680 final long identity = Binder.clearCallingIdentity();
1681 try {
1682 final Phone phone = getPhone(subId);
1683 if (phone == null) {
1684 return false;
1685 }
1686 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1687 toggleRadioOnOffForSubscriber(subId);
1688 }
1689 return true;
1690 } finally {
1691 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001692 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001693 }
Wink Saville36469e72014-06-11 15:17:00 -07001694
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001695 public boolean needMobileRadioShutdown() {
1696 /*
1697 * If any of the Radios are available, it will need to be
1698 * shutdown. So return true if any Radio is available.
1699 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001700 final long identity = Binder.clearCallingIdentity();
1701 try {
1702 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1703 Phone phone = PhoneFactory.getPhone(i);
1704 if (phone != null && phone.isRadioAvailable()) return true;
1705 }
1706 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1707 return false;
1708 } finally {
1709 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001710 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001711 }
1712
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001713 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001714 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001715 enforceModifyPermission();
1716
1717 final long identity = Binder.clearCallingIdentity();
1718 try {
1719 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1720 logv("Shutting down Phone " + i);
1721 shutdownRadioUsingPhoneId(i);
1722 }
1723 } finally {
1724 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001725 }
1726 }
1727
1728 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001729 Phone phone = PhoneFactory.getPhone(phoneId);
1730 if (phone != null && phone.isRadioAvailable()) {
1731 phone.shutdownRadio();
1732 }
1733 }
1734
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001735 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001736 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001737
1738 final long identity = Binder.clearCallingIdentity();
1739 try {
1740 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1741 if (defaultPhone != null) {
1742 defaultPhone.setRadioPower(turnOn);
1743 return true;
1744 } else {
1745 loge("There's no default phone.");
1746 return false;
1747 }
1748 } finally {
1749 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001750 }
Wink Saville36469e72014-06-11 15:17:00 -07001751 }
1752
Wink Savilleb564aae2014-10-23 10:18:09 -07001753 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001754 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001755
1756 final long identity = Binder.clearCallingIdentity();
1757 try {
1758 final Phone phone = getPhone(subId);
1759 if (phone != null) {
1760 phone.setRadioPower(turnOn);
1761 return true;
1762 } else {
1763 return false;
1764 }
1765 } finally {
1766 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001767 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001768 }
1769
Wink Saville36469e72014-06-11 15:17:00 -07001770 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001771 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001772 public boolean enableDataConnectivity() {
1773 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001774
1775 final long identity = Binder.clearCallingIdentity();
1776 try {
1777 int subId = mSubscriptionController.getDefaultDataSubId();
1778 final Phone phone = getPhone(subId);
1779 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001780 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001781 return true;
1782 } else {
1783 return false;
1784 }
1785 } finally {
1786 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001787 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001788 }
1789
Wink Saville36469e72014-06-11 15:17:00 -07001790 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001791 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001792 public boolean disableDataConnectivity() {
1793 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001794
1795 final long identity = Binder.clearCallingIdentity();
1796 try {
1797 int subId = mSubscriptionController.getDefaultDataSubId();
1798 final Phone phone = getPhone(subId);
1799 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001800 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001801 return true;
1802 } else {
1803 return false;
1804 }
1805 } finally {
1806 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001807 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001808 }
1809
Sanket Padawe356d7632015-06-22 14:03:32 -07001810 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001811 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001812 final long identity = Binder.clearCallingIdentity();
1813 try {
1814 final Phone phone = getPhone(subId);
1815 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001816 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001817 } else {
1818 return false;
1819 }
1820 } finally {
1821 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001822 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001823 }
1824
1825 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001826 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001827 }
1828
pkanwarae03a6b2016-11-06 20:37:09 -08001829 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001830 enforceCallPermission();
1831
1832 final long identity = Binder.clearCallingIdentity();
1833 try {
1834 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1835 return;
1836 }
1837 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1838 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1839 } finally {
1840 Binder.restoreCallingIdentity(identity);
1841 }
pkanwar32d516d2016-10-14 19:37:38 -07001842 };
1843
Wink Savilleb564aae2014-10-23 10:18:09 -07001844 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001845 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001846
1847 final long identity = Binder.clearCallingIdentity();
1848 try {
1849 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1850 return false;
1851 }
1852 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1853 } finally {
1854 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001855 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001856 }
1857
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001858 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001859 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001860 }
1861
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001862 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001863 final long identity = Binder.clearCallingIdentity();
1864 try {
1865 Phone phone = PhoneFactory.getPhone(slotIndex);
1866 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1867 PhoneConstantConversions.convertCallState(phone.getState());
1868 } finally {
1869 Binder.restoreCallingIdentity(identity);
1870 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001871 }
1872
Sanket Padawe356d7632015-06-22 14:03:32 -07001873 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001874 public int getDataState() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001875 final long identity = Binder.clearCallingIdentity();
1876 try {
1877 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1878 if (phone != null) {
1879 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1880 } else {
1881 return PhoneConstantConversions.convertDataState(
1882 PhoneConstants.DataState.DISCONNECTED);
1883 }
1884 } finally {
1885 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001886 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001887 }
1888
Sanket Padawe356d7632015-06-22 14:03:32 -07001889 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001890 public int getDataActivity() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001891 final long identity = Binder.clearCallingIdentity();
1892 try {
1893 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1894 if (phone != null) {
1895 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1896 } else {
1897 return TelephonyManager.DATA_ACTIVITY_NONE;
1898 }
1899 } finally {
1900 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001901 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001902 }
1903
1904 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001905 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001906 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001907 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08001908
1909 LocationAccessPolicy.LocationPermissionResult locationResult =
1910 LocationAccessPolicy.checkLocationPermission(mApp,
1911 new LocationAccessPolicy.LocationPermissionQuery.Builder()
1912 .setCallingPackage(callingPackage)
1913 .setCallingPid(Binder.getCallingPid())
1914 .setCallingUid(Binder.getCallingUid())
1915 .setMethod("getCellLocation")
Hall Liuc3f8eb62020-01-24 18:07:12 -08001916 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08001917 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
1918 .build());
1919 switch (locationResult) {
1920 case DENIED_HARD:
1921 throw new SecurityException("Not allowed to access cell location");
1922 case DENIED_SOFT:
1923 return new Bundle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001924 }
1925
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001926 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001927 final long identity = Binder.clearCallingIdentity();
1928 try {
1929 if (DBG_LOC) log("getCellLocation: is active user");
1930 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001931 int subId = mSubscriptionController.getDefaultDataSubId();
1932 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1933 cl.fillInNotifierBundle(data);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001934 return data;
1935 } finally {
1936 Binder.restoreCallingIdentity(identity);
1937 }
Svetoslav64fad262015-04-14 14:35:21 -07001938 }
1939
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001940 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001941 public String getNetworkCountryIsoForPhone(int phoneId) {
1942 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1943 // registered cell info, so return a NULL country instead.
1944 final long identity = Binder.clearCallingIdentity();
1945 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001946 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1947 // Get default phone in this case.
1948 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1949 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001950 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001951 // Todo: fix this when we can get the actual cellular network info when the device
1952 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001953 if (TelephonyManager.NETWORK_TYPE_IWLAN
1954 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1955 return "";
1956 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001957 Phone phone = PhoneFactory.getPhone(phoneId);
1958 if (phone != null) {
1959 ServiceStateTracker sst = phone.getServiceStateTracker();
1960 if (sst != null) {
1961 LocaleTracker lt = sst.getLocaleTracker();
1962 if (lt != null) {
1963 return lt.getCurrentCountry();
1964 }
1965 }
1966 }
1967 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001968 } finally {
1969 Binder.restoreCallingIdentity(identity);
1970 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001971 }
1972
1973 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001974 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001975 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001976 }
1977
Sanket Padawe356d7632015-06-22 14:03:32 -07001978 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001979 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001980 mApp.enforceCallingOrSelfPermission(
1981 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001982
1983 final long identity = Binder.clearCallingIdentity();
1984 try {
1985 final Phone phone = getPhone(subId);
1986 if (phone != null) {
1987 phone.enableLocationUpdates();
1988 }
1989 } finally {
1990 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001991 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001992 }
1993
1994 @Override
1995 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001996 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001997 }
1998
Sanket Padawe356d7632015-06-22 14:03:32 -07001999 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002000 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002001 mApp.enforceCallingOrSelfPermission(
2002 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002003
2004 final long identity = Binder.clearCallingIdentity();
2005 try {
2006 final Phone phone = getPhone(subId);
2007 if (phone != null) {
2008 phone.disableLocationUpdates();
2009 }
2010 } finally {
2011 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002012 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002013 }
2014
Nathan Harold31d7ff32018-10-15 20:20:30 -07002015 /**
2016 * Returns the target SDK version number for a given package name.
2017 *
2018 * @return target SDK if the package is found or INT_MAX.
2019 */
2020 private int getTargetSdk(String packageName) {
2021 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002022 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(
2023 packageName, 0);
Nathan Harold31d7ff32018-10-15 20:20:30 -07002024 if (ai != null) return ai.targetSdkVersion;
2025 } catch (PackageManager.NameNotFoundException unexpected) {
2026 }
2027 return Integer.MAX_VALUE;
2028 }
2029
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002030 @Override
2031 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07002032 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
2033 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002034 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2035 throw new SecurityException(
2036 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2037 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002038
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002039 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
2040 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2041 return null;
2042 }
Svetoslav64fad262015-04-14 14:35:21 -07002043
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002044 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002045
Nathan Haroldf180aac2018-06-01 18:43:55 -07002046 List<CellInfo> info = getAllCellInfo(callingPackage);
2047 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002048
Nathan Haroldf180aac2018-06-01 18:43:55 -07002049 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2050 for (CellInfo ci : info) {
2051 if (ci instanceof CellInfoGsm) {
2052 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2053 } else if (ci instanceof CellInfoWcdma) {
2054 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2055 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002056 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002057 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002058 }
2059
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002060 private List<CellInfo> getCachedCellInfo() {
2061 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2062 for (Phone phone : PhoneFactory.getPhones()) {
2063 List<CellInfo> info = phone.getAllCellInfo();
2064 if (info != null) cellInfos.addAll(info);
2065 }
2066 return cellInfos;
2067 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002068
2069 @Override
Svetoslav64fad262015-04-14 14:35:21 -07002070 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002071 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002072 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002073
2074 LocationAccessPolicy.LocationPermissionResult locationResult =
2075 LocationAccessPolicy.checkLocationPermission(mApp,
2076 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2077 .setCallingPackage(callingPackage)
2078 .setCallingPid(Binder.getCallingPid())
2079 .setCallingUid(Binder.getCallingUid())
2080 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002081 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002082 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2083 .build());
2084 switch (locationResult) {
2085 case DENIED_HARD:
2086 throw new SecurityException("Not allowed to access cell info");
2087 case DENIED_SOFT:
2088 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002089 }
2090
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002091 final int targetSdk = getTargetSdk(callingPackage);
2092 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2093 return getCachedCellInfo();
2094 }
2095
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002096 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002097 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002098 final long identity = Binder.clearCallingIdentity();
2099 try {
2100 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2101 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002102 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002103 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002104 if (info != null) cellInfos.addAll(info);
2105 }
2106 return cellInfos;
2107 } finally {
2108 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002109 }
2110 }
2111
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002112 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002113 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2114 requestCellInfoUpdateInternal(
2115 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2116 }
2117
2118 @Override
2119 public void requestCellInfoUpdateWithWorkSource(
2120 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2121 enforceModifyPermission();
2122 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2123 }
2124
2125 private void requestCellInfoUpdateInternal(
2126 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002127 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002128 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002129
2130 LocationAccessPolicy.LocationPermissionResult locationResult =
2131 LocationAccessPolicy.checkLocationPermission(mApp,
2132 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2133 .setCallingPackage(callingPackage)
2134 .setCallingPid(Binder.getCallingPid())
2135 .setCallingUid(Binder.getCallingUid())
2136 .setMethod("requestCellInfoUpdate")
2137 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2138 .build());
2139 switch (locationResult) {
2140 case DENIED_HARD:
2141 throw new SecurityException("Not allowed to access cell info");
2142 case DENIED_SOFT:
Nathan Haroldb3c5da42019-05-09 10:26:08 -07002143 try {
2144 cb.onCellInfo(new ArrayList<CellInfo>());
2145 } catch (RemoteException re) {
2146 // Drop without consequences
2147 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002148 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002149 }
2150
Nathan Harold32e84c42019-05-09 10:13:47 -07002151
2152 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002153 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2154
2155 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2156 }
2157
2158 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002159 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002160 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002161 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002162
2163 final long identity = Binder.clearCallingIdentity();
2164 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002165 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002166 } finally {
2167 Binder.restoreCallingIdentity(identity);
2168 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002169 }
2170
Shishir Agrawala9f32182016-04-12 12:00:16 -07002171 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002172 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002173 Phone phone = PhoneFactory.getPhone(slotIndex);
2174 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002175 return null;
2176 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002177 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002178 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2179 callingPackage, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002180 return null;
2181 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002182
2183 final long identity = Binder.clearCallingIdentity();
2184 try {
2185 return phone.getImei();
2186 } finally {
2187 Binder.restoreCallingIdentity(identity);
2188 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002189 }
2190
2191 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002192 public String getTypeAllocationCodeForSlot(int slotIndex) {
2193 Phone phone = PhoneFactory.getPhone(slotIndex);
2194 String tac = null;
2195 if (phone != null) {
2196 String imei = phone.getImei();
2197 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2198 }
2199 return tac;
2200 }
2201
2202 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002203 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002204 Phone phone = PhoneFactory.getPhone(slotIndex);
2205 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002206 return null;
2207 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002208
Jeff Davidson913390f2018-02-23 17:11:49 -08002209 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002210 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2211 callingPackage, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002212 return null;
2213 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002214
2215 final long identity = Binder.clearCallingIdentity();
2216 try {
2217 return phone.getMeid();
2218 } finally {
2219 Binder.restoreCallingIdentity(identity);
2220 }
Jack Yu2af8d712017-03-15 17:14:14 -07002221 }
2222
2223 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002224 public String getManufacturerCodeForSlot(int slotIndex) {
2225 Phone phone = PhoneFactory.getPhone(slotIndex);
2226 String manufacturerCode = null;
2227 if (phone != null) {
2228 String meid = phone.getMeid();
2229 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2230 }
2231 return manufacturerCode;
2232 }
2233
2234 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002235 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002236 Phone phone = PhoneFactory.getPhone(slotIndex);
2237 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002238 return null;
2239 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002240 int subId = phone.getSubId();
2241 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2242 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2243 return null;
2244 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002245
2246 final long identity = Binder.clearCallingIdentity();
2247 try {
2248 return phone.getDeviceSvn();
2249 } finally {
2250 Binder.restoreCallingIdentity(identity);
2251 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002252 }
2253
fionaxu43304da2017-11-27 22:51:16 -08002254 @Override
2255 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002256 final long identity = Binder.clearCallingIdentity();
2257 try {
2258 final Phone phone = getPhone(subId);
2259 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2260 } finally {
2261 Binder.restoreCallingIdentity(identity);
2262 }
fionaxu43304da2017-11-27 22:51:16 -08002263 }
2264
2265 @Override
2266 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002267 final long identity = Binder.clearCallingIdentity();
2268 try {
2269 final Phone phone = getPhone(subId);
2270 return phone == null ? null : phone.getCarrierName();
2271 } finally {
2272 Binder.restoreCallingIdentity(identity);
2273 }
fionaxu43304da2017-11-27 22:51:16 -08002274 }
2275
calvinpanffe225e2018-11-01 19:43:06 +08002276 @Override
chen xu0026ca62019-03-06 15:28:50 -08002277 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002278 final long identity = Binder.clearCallingIdentity();
2279 try {
2280 final Phone phone = getPhone(subId);
2281 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002282 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002283 } finally {
2284 Binder.restoreCallingIdentity(identity);
2285 }
2286 }
2287
2288 @Override
chen xu0026ca62019-03-06 15:28:50 -08002289 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002290 final long identity = Binder.clearCallingIdentity();
2291 try {
2292 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002293 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002294 } finally {
2295 Binder.restoreCallingIdentity(identity);
2296 }
2297 }
2298
chen xu651eec72018-11-11 19:03:44 -08002299 @Override
chen xu864e11c2018-12-06 22:10:03 -08002300 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2301 if (!isSubscriptionMccMnc) {
2302 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2303 }
chen xu651eec72018-11-11 19:03:44 -08002304 final Phone phone = PhoneFactory.getPhone(slotIndex);
2305 if (phone == null) {
2306 return TelephonyManager.UNKNOWN_CARRIER_ID;
2307 }
2308 final long identity = Binder.clearCallingIdentity();
2309 try {
2310 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2311 } finally {
2312 Binder.restoreCallingIdentity(identity);
2313 }
2314 }
2315
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002316 //
2317 // Internal helper methods.
2318 //
2319
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002320 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002321 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2322 *
2323 * @throws SecurityException if the caller does not have the required permission
2324 */
2325 private void enforceModifyPermission() {
2326 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2327 }
2328
2329 /**
2330 * Make sure the caller has the CALL_PHONE permission.
2331 *
2332 * @throws SecurityException if the caller does not have the required permission
2333 */
2334 private void enforceCallPermission() {
2335 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2336 }
2337
Stuart Scott8eef64f2015-04-08 15:13:54 -07002338 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002339 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002340 "ConnectivityService");
2341 }
2342
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002343 private String createTelUrl(String number) {
2344 if (TextUtils.isEmpty(number)) {
2345 return null;
2346 }
2347
Jake Hambye994d462014-02-03 13:10:13 -08002348 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002349 }
2350
Ihab Awadf9e92732013-12-05 18:02:52 -08002351 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002352 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2353 }
2354
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002355 private static void logv(String msg) {
2356 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2357 }
2358
Ihab Awadf9e92732013-12-05 18:02:52 -08002359 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002360 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2361 }
2362
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002363 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002364 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002365 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002366 }
2367
Sanket Padawe356d7632015-06-22 14:03:32 -07002368 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002369 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002370 final long identity = Binder.clearCallingIdentity();
2371 try {
2372 final Phone phone = PhoneFactory.getPhone(slotIndex);
2373 if (phone == null) {
2374 return PhoneConstants.PHONE_TYPE_NONE;
2375 } else {
2376 return phone.getPhoneType();
2377 }
2378 } finally {
2379 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002380 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002381 }
2382
2383 /**
2384 * Returns the CDMA ERI icon index to display
2385 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002386 @Override
2387 public int getCdmaEriIconIndex(String callingPackage) {
2388 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002389 }
2390
Sanket Padawe356d7632015-06-22 14:03:32 -07002391 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002392 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002393 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002394 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002395 return -1;
2396 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002397
2398 final long identity = Binder.clearCallingIdentity();
2399 try {
2400 final Phone phone = getPhone(subId);
2401 if (phone != null) {
2402 return phone.getCdmaEriIconIndex();
2403 } else {
2404 return -1;
2405 }
2406 } finally {
2407 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002408 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002409 }
2410
2411 /**
2412 * Returns the CDMA ERI icon mode,
2413 * 0 - ON
2414 * 1 - FLASHING
2415 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002416 @Override
2417 public int getCdmaEriIconMode(String callingPackage) {
2418 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002419 }
2420
Sanket Padawe356d7632015-06-22 14:03:32 -07002421 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002422 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002423 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002424 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002425 return -1;
2426 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002427
2428 final long identity = Binder.clearCallingIdentity();
2429 try {
2430 final Phone phone = getPhone(subId);
2431 if (phone != null) {
2432 return phone.getCdmaEriIconMode();
2433 } else {
2434 return -1;
2435 }
2436 } finally {
2437 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002438 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002439 }
2440
2441 /**
2442 * Returns the CDMA ERI text,
2443 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002444 @Override
2445 public String getCdmaEriText(String callingPackage) {
2446 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002447 }
2448
Sanket Padawe356d7632015-06-22 14:03:32 -07002449 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002450 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002451 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002452 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002453 return null;
2454 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002455
2456 final long identity = Binder.clearCallingIdentity();
2457 try {
2458 final Phone phone = getPhone(subId);
2459 if (phone != null) {
2460 return phone.getCdmaEriText();
2461 } else {
2462 return null;
2463 }
2464 } finally {
2465 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002466 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002467 }
2468
2469 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002470 * Returns the CDMA MDN.
2471 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002472 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002473 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002474 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2475 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002476
2477 final long identity = Binder.clearCallingIdentity();
2478 try {
2479 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002480 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002481 return phone.getLine1Number();
2482 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002483 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002484 return null;
2485 }
2486 } finally {
2487 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002488 }
2489 }
2490
2491 /**
2492 * Returns the CDMA MIN.
2493 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002494 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002495 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002496 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2497 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002498
2499 final long identity = Binder.clearCallingIdentity();
2500 try {
2501 final Phone phone = getPhone(subId);
2502 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2503 return phone.getCdmaMin();
2504 } else {
2505 return null;
2506 }
2507 } finally {
2508 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002509 }
2510 }
2511
Hall Liud892bec2018-11-30 14:51:45 -08002512 @Override
2513 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2514 INumberVerificationCallback callback, String callingPackage) {
2515 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2516 != PERMISSION_GRANTED) {
2517 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2518 }
2519 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2520
2521 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2522 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2523 throw new SecurityException("Calling package must be configured in the device config");
2524 }
2525
2526 if (range == null) {
2527 throw new NullPointerException("Range must be non-null");
2528 }
2529
2530 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002531 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002532
2533 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2534 }
2535
Junda Liuca05d5d2014-08-14 22:36:34 -07002536 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002537 * Returns true if CDMA provisioning needs to run.
2538 */
2539 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002540 final long identity = Binder.clearCallingIdentity();
2541 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002542 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002543 } finally {
2544 Binder.restoreCallingIdentity(identity);
2545 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002546 }
2547
2548 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002549 * Sets the voice mail number of a given subId.
2550 */
2551 @Override
2552 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002553 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002554
2555 final long identity = Binder.clearCallingIdentity();
2556 try {
2557 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2558 new Pair<String, String>(alphaTag, number), new Integer(subId));
2559 return success;
2560 } finally {
2561 Binder.restoreCallingIdentity(identity);
2562 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002563 }
2564
Ta-wei Yen87c49842016-05-13 21:19:52 -07002565 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002566 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2567 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002568 String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002569 if (!TextUtils.equals(callingPackage, systemDialer)) {
2570 throw new SecurityException("caller must be system dialer");
2571 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002572
2573 final long identity = Binder.clearCallingIdentity();
2574 try {
2575 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2576 if (phoneAccountHandle == null) {
2577 return null;
2578 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002579 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002580 } finally {
2581 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002582 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002583 }
2584
2585 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002586 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002587 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002588 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002589 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002590 return null;
2591 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002592
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002593 final long identity = Binder.clearCallingIdentity();
2594 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002595 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002596 } finally {
2597 Binder.restoreCallingIdentity(identity);
2598 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002599 }
2600
2601 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002602 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2603 VisualVoicemailSmsFilterSettings settings) {
2604 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002605
2606 final long identity = Binder.clearCallingIdentity();
2607 try {
2608 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002609 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002610 } finally {
2611 Binder.restoreCallingIdentity(identity);
2612 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002613 }
2614
2615 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002616 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2617 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002618
2619 final long identity = Binder.clearCallingIdentity();
2620 try {
2621 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002622 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002623 } finally {
2624 Binder.restoreCallingIdentity(identity);
2625 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002626 }
2627
2628 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002629 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2630 String callingPackage, int subId) {
2631 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002632
2633 final long identity = Binder.clearCallingIdentity();
2634 try {
2635 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002636 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002637 } finally {
2638 Binder.restoreCallingIdentity(identity);
2639 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002640 }
2641
2642 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002643 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002644 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002645
2646 final long identity = Binder.clearCallingIdentity();
2647 try {
2648 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002649 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002650 } finally {
2651 Binder.restoreCallingIdentity(identity);
2652 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002653 }
2654
2655 @Override
2656 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2657 String number, int port, String text, PendingIntent sentIntent) {
2658 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002659 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002660 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07002661 SmsController smsController = PhoneFactory.getSmsController();
2662 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
2663 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002664 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07002665
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002666 /**
fionaxu0152e512016-11-14 13:36:14 -08002667 * Sets the voice activation state of a given subId.
2668 */
2669 @Override
2670 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002671 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2672 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002673
2674 final long identity = Binder.clearCallingIdentity();
2675 try {
2676 final Phone phone = getPhone(subId);
2677 if (phone != null) {
2678 phone.setVoiceActivationState(activationState);
2679 } else {
2680 loge("setVoiceActivationState fails with invalid subId: " + subId);
2681 }
2682 } finally {
2683 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002684 }
2685 }
2686
2687 /**
2688 * Sets the data activation state of a given subId.
2689 */
2690 @Override
2691 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002692 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2693 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002694
2695 final long identity = Binder.clearCallingIdentity();
2696 try {
2697 final Phone phone = getPhone(subId);
2698 if (phone != null) {
2699 phone.setDataActivationState(activationState);
2700 } else {
2701 loge("setVoiceActivationState fails with invalid subId: " + subId);
2702 }
2703 } finally {
2704 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002705 }
2706 }
2707
2708 /**
2709 * Returns the voice activation state of a given subId.
2710 */
2711 @Override
2712 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002713 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002714
fionaxu0152e512016-11-14 13:36:14 -08002715 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002716 final long identity = Binder.clearCallingIdentity();
2717 try {
2718 if (phone != null) {
2719 return phone.getVoiceActivationState();
2720 } else {
2721 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2722 }
2723 } finally {
2724 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002725 }
2726 }
2727
2728 /**
2729 * Returns the data activation state of a given subId.
2730 */
2731 @Override
2732 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002733 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002734
fionaxu0152e512016-11-14 13:36:14 -08002735 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002736 final long identity = Binder.clearCallingIdentity();
2737 try {
2738 if (phone != null) {
2739 return phone.getDataActivationState();
2740 } else {
2741 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2742 }
2743 } finally {
2744 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002745 }
2746 }
2747
2748 /**
Wink Saville36469e72014-06-11 15:17:00 -07002749 * Returns the unread count of voicemails for a subId
2750 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002751 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002752 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2753 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2754 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2755 return 0;
2756 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002757 final long identity = Binder.clearCallingIdentity();
2758 try {
2759 final Phone phone = getPhone(subId);
2760 if (phone != null) {
2761 return phone.getVoiceMessageCount();
2762 } else {
2763 return 0;
2764 }
2765 } finally {
2766 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002767 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002768 }
2769
2770 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002771 * returns true, if the device is in a state where both voice and data
2772 * are supported simultaneously. This can change based on location or network condition.
2773 */
2774 @Override
2775 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002776 final long identity = Binder.clearCallingIdentity();
2777 try {
2778 final Phone phone = getPhone(subId);
2779 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2780 } finally {
2781 Binder.restoreCallingIdentity(identity);
2782 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002783 }
2784
2785 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002786 * Send the dialer code if called from the current default dialer or the caller has
2787 * carrier privilege.
2788 * @param inputCode The dialer code to send
2789 */
2790 @Override
2791 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002792 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002793 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002794 String defaultDialer = TelecomManager.from(defaultPhone.getContext())
2795 .getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002796 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002797 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2798 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002799 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002800
2801 final long identity = Binder.clearCallingIdentity();
2802 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002803 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002804 } finally {
2805 Binder.restoreCallingIdentity(identity);
2806 }
fionaxu235cc5e2017-03-06 22:25:57 -08002807 }
2808
Pengquan Menga1bb6272018-09-06 09:59:22 -07002809 @Override
2810 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002811 if (!isActiveSubscription(subId)) {
2812 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2813 }
2814
Pengquan Menga1bb6272018-09-06 09:59:22 -07002815 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2816 }
2817
Brad Ebinger35c841c2018-10-01 10:40:55 -07002818 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002819 public boolean isInEmergencySmsMode() {
2820 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2821 final long identity = Binder.clearCallingIdentity();
2822 try {
2823 for (Phone phone : PhoneFactory.getPhones()) {
2824 if (phone.isInEmergencySmsMode()) {
2825 return true;
2826 }
2827 }
2828 } finally {
2829 Binder.restoreCallingIdentity(identity);
2830 }
2831 return false;
2832 }
2833
2834 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002835 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2836 throws RemoteException {
2837 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002838 final long token = Binder.clearCallingIdentity();
2839 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002840 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002841 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002842 .addRegistrationCallbackForSubscription(c, subId);
2843 } finally {
2844 Binder.restoreCallingIdentity(token);
2845 }
2846 }
2847
2848 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002849 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2850 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002851 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2852 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2853 }
2854 Binder.withCleanCallingIdentity(() -> {
2855 try {
2856 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002857 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002858 .removeRegistrationCallbackForSubscription(c, subId);
2859 } catch (IllegalArgumentException e) {
2860 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2861 + "is inactive, ignoring unregister.");
2862 // If the subscription is no longer active, just return, since the callback
2863 // will already have been removed internally.
2864 }
2865 });
Brad Ebinger35c841c2018-10-01 10:40:55 -07002866 }
2867
2868 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002869 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2870 throws RemoteException {
2871 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002872 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2873 final long token = Binder.clearCallingIdentity();
2874 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002875 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002876 .addCapabilitiesCallbackForSubscription(c, subId);
2877 } finally {
2878 Binder.restoreCallingIdentity(token);
2879 }
2880 }
2881
2882 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002883 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2884 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002885
2886 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2887 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2888 }
2889 Binder.withCleanCallingIdentity(() -> {
2890 try {
2891 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002892 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002893 .removeCapabilitiesCallbackForSubscription(c, subId);
2894 } catch (IllegalArgumentException e) {
2895 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
2896 + "is inactive, ignoring unregister.");
2897 // If the subscription is no longer active, just return, since the callback
2898 // will already have been removed internally.
2899 }
2900 });
Brad Ebinger35c841c2018-10-01 10:40:55 -07002901 }
2902
2903 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002904 public boolean isCapable(int subId, int capability, int regTech) {
2905 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002906 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2907 final long token = Binder.clearCallingIdentity();
2908 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002909 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002910 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2911 } catch (ImsException e) {
2912 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2913 return false;
Brad Ebinger6b5ac222019-02-04 14:36:52 -08002914 } catch (IllegalArgumentException e) {
2915 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
2916 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07002917 } finally {
2918 Binder.restoreCallingIdentity(token);
2919 }
2920 }
2921
2922 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002923 public boolean isAvailable(int subId, int capability, int regTech) {
2924 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002925 final long token = Binder.clearCallingIdentity();
2926 try {
2927 Phone phone = getPhone(subId);
2928 if (phone == null) return false;
2929 return phone.isImsCapabilityAvailable(capability, regTech);
2930 } finally {
2931 Binder.restoreCallingIdentity(token);
2932 }
2933 }
2934
2935 @Override
2936 public boolean isAdvancedCallingSettingEnabled(int subId) {
2937 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2938 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2939 final long token = Binder.clearCallingIdentity();
2940 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002941 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002942 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2943 } finally {
2944 Binder.restoreCallingIdentity(token);
2945 }
2946 }
2947
2948 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08002949 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002950 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08002951 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002952 final long identity = Binder.clearCallingIdentity();
2953 try {
2954 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002955 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002956 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2957 } finally {
2958 Binder.restoreCallingIdentity(identity);
2959 }
2960 }
2961
2962 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002963 public boolean isVtSettingEnabled(int subId) {
2964 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002965 final long identity = Binder.clearCallingIdentity();
2966 try {
2967 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002968 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002969 getSlotIndexOrException(subId)).isVtEnabledByUser();
2970 } finally {
2971 Binder.restoreCallingIdentity(identity);
2972 }
2973 }
2974
2975 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08002976 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002977 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08002978 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002979 final long identity = Binder.clearCallingIdentity();
2980 try {
2981 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002982 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger35c841c2018-10-01 10:40:55 -07002983 } finally {
2984 Binder.restoreCallingIdentity(identity);
2985 }
2986 }
2987
2988 @Override
2989 public boolean isVoWiFiSettingEnabled(int subId) {
2990 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
2991 final long identity = Binder.clearCallingIdentity();
2992 try {
2993 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002994 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002995 getSlotIndexOrException(subId)).isWfcEnabledByUser();
2996 } finally {
2997 Binder.restoreCallingIdentity(identity);
2998 }
2999 }
3000
3001 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003002 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003003 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003004 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003005 final long identity = Binder.clearCallingIdentity();
3006 try {
3007 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003008 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003009 } finally {
3010 Binder.restoreCallingIdentity(identity);
3011 }
3012 }
3013
3014 @Override
3015 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3016 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3017 final long identity = Binder.clearCallingIdentity();
3018 try {
3019 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003020 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003021 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
3022 } finally {
3023 Binder.restoreCallingIdentity(identity);
3024 }
3025 }
3026
3027 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003028 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003029 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003030 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003031 final long identity = Binder.clearCallingIdentity();
3032 try {
3033 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003034 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003035 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
3036 } finally {
3037 Binder.restoreCallingIdentity(identity);
3038 }
3039 }
3040
3041 @Override
3042 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3043 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3044 "setVoWiFiNonPersistent");
3045 final long identity = Binder.clearCallingIdentity();
3046 try {
3047 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003048 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003049 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003050 } finally {
3051 Binder.restoreCallingIdentity(identity);
3052 }
3053 }
3054
3055 @Override
3056 public int getVoWiFiModeSetting(int subId) {
3057 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3058 final long identity = Binder.clearCallingIdentity();
3059 try {
3060 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003061 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003062 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
3063 } finally {
3064 Binder.restoreCallingIdentity(identity);
3065 }
3066 }
3067
3068 @Override
3069 public void setVoWiFiModeSetting(int subId, int mode) {
3070 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3071 "setVoWiFiModeSetting");
3072 final long identity = Binder.clearCallingIdentity();
3073 try {
3074 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003075 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003076 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
3077 } finally {
3078 Binder.restoreCallingIdentity(identity);
3079 }
3080 }
3081
3082 @Override
3083 public int getVoWiFiRoamingModeSetting(int subId) {
3084 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3085 final long identity = Binder.clearCallingIdentity();
3086 try {
3087 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003088 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003089 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
3090 } finally {
3091 Binder.restoreCallingIdentity(identity);
3092 }
3093 }
3094
3095 @Override
3096 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3097 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3098 "setVoWiFiRoamingModeSetting");
3099 final long identity = Binder.clearCallingIdentity();
3100 try {
3101 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003102 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003103 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
3104 } finally {
3105 Binder.restoreCallingIdentity(identity);
3106 }
3107 }
3108
3109 @Override
3110 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3111 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3112 "setRttCapabilityEnabled");
3113 final long identity = Binder.clearCallingIdentity();
3114 try {
3115 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003116 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003117 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3118 } finally {
3119 Binder.restoreCallingIdentity(identity);
3120 }
3121 }
3122
3123 @Override
3124 public boolean isTtyOverVolteEnabled(int subId) {
3125 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3126 final long identity = Binder.clearCallingIdentity();
3127 try {
3128 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003129 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003130 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
3131 } finally {
3132 Binder.restoreCallingIdentity(identity);
3133 }
3134 }
3135
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003136 @Override
3137 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3138 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3139 final long identity = Binder.clearCallingIdentity();
3140 try {
3141 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003142 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003143 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003144 } finally {
3145 Binder.restoreCallingIdentity(identity);
3146 }
3147 }
3148
3149 @Override
3150 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3151 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3152 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003153 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3154 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3155 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003156 try {
3157 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003158 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003159 .removeProvisioningCallbackForSubscription(callback, subId);
3160 } catch (IllegalArgumentException e) {
3161 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3162 + "is inactive, ignoring unregister.");
3163 // If the subscription is no longer active, just return, since the callback will already
3164 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003165 } finally {
3166 Binder.restoreCallingIdentity(identity);
3167 }
3168 }
3169
3170 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003171 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3172 boolean isProvisioned) {
3173 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3174 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3175 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3176 }
3177 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3178 "setProvisioningStatusForCapability");
3179 final long identity = Binder.clearCallingIdentity();
3180 try {
3181 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3182 Phone phone = getPhone(subId);
3183 if (phone == null) {
3184 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3185 + subId);
3186 return;
3187 }
3188 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3189 return;
3190 }
3191
3192 // this capability requires provisioning, route to the correct API.
3193 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3194 switch (capability) {
3195 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3196 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3197 ims.setVolteProvisioned(isProvisioned);
3198 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3199 ims.setWfcProvisioned(isProvisioned);
3200 }
3201 break;
3202 }
3203 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3204 // There is currently no difference in VT provisioning type.
3205 ims.setVtProvisioned(isProvisioned);
3206 break;
3207 }
3208 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3209 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3210 // change the capability of the feature instead if needed.
3211 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3212 == isProvisioned) {
3213 // No change in provisioning.
3214 return;
3215 }
3216 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3217 try {
3218 ims.changeMmTelCapability(capability, tech, isProvisioned);
3219 } catch (ImsException e) {
3220 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3221 + ", Exception" + e.getMessage());
3222 }
3223 break;
3224 }
3225 default: {
3226 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3227 + capability + "', which does not require provisioning.");
3228 }
3229 }
3230
3231 } finally {
3232 Binder.restoreCallingIdentity(identity);
3233 }
3234 }
3235
3236 @Override
3237 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3238 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3239 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3240 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3241 }
3242 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3243 final long identity = Binder.clearCallingIdentity();
3244 try {
3245 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3246 Phone phone = getPhone(subId);
3247 if (phone == null) {
3248 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3249 + subId);
3250 // We will fail with "true" as the provisioning status because this is the default
3251 // if we do not require provisioning.
3252 return true;
3253 }
3254
3255 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3256 return true;
3257 }
3258
3259 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3260 switch (capability) {
3261 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3262 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3263 return ims.isVolteProvisionedOnDevice();
3264 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3265 return ims.isWfcProvisionedOnDevice();
3266 }
3267 // This should never happen, since we are checking tech above to make sure it
3268 // is either LTE or IWLAN.
3269 throw new IllegalArgumentException("Invalid radio technology for voice "
3270 + "capability.");
3271 }
3272 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3273 // There is currently no difference in VT provisioning type.
3274 return ims.isVtProvisionedOnDevice();
3275 }
3276 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3277 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3278 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3279 }
3280 default: {
3281 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3282 + capability + "', which does not require provisioning.");
3283 }
3284 }
3285
3286 } finally {
3287 Binder.restoreCallingIdentity(identity);
3288 }
3289 }
3290
3291 @Override
3292 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3293 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3294 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3295 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3296 }
3297 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3298 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3299 return (provisionedBits & capability) > 0;
3300 }
3301
3302 @Override
3303 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3304 boolean isProvisioned) {
3305 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3306 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3307 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3308 }
3309 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3310 "setProvisioningStatusForCapability");
3311 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3312 // If the current provisioning status for capability already matches isProvisioned,
3313 // do nothing.
3314 if (((provisionedBits & capability) > 0) == isProvisioned) {
3315 return;
3316 }
3317 if (isProvisioned) {
3318 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3319 } else {
3320 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3321 }
3322 }
3323
3324 /**
3325 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3326 * technology. The bitfield should mirror the bitfield defined by
3327 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3328 */
3329 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3330 String key = getMmTelProvisioningKey(subId, tech);
3331 // Default is no capabilities are provisioned.
3332 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3333 }
3334
3335 /**
3336 * Sets the MmTel capability provisioning bitfield (defined by
3337 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3338 * technology specified.
3339 *
3340 * Note: This is a synchronous command and should not be called on UI thread.
3341 */
3342 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3343 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3344 String key = getMmTelProvisioningKey(subId, tech);
3345 editor.putInt(key, newField);
3346 editor.commit();
3347 }
3348
3349 private static String getMmTelProvisioningKey(int subId, int tech) {
3350 // resulting key is provision_ims_mmtel_{subId}_{tech}
3351 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3352 }
3353
3354 /**
3355 * Query CarrierConfig to see if the specified capability requires provisioning for the
3356 * carrier associated with the subscription id.
3357 */
3358 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3359 int capability) {
3360 CarrierConfigManager configManager = new CarrierConfigManager(context);
3361 PersistableBundle c = configManager.getConfigForSubId(subId);
3362 boolean requireUtProvisioning = c.getBoolean(
3363 // By default, this config is true (even if there is no SIM). We also check to make
3364 // sure the subscription needs provisioning here, so we do not need to check for
3365 // the no-SIM case, where we would normally shortcut this to false.
3366 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, true)
3367 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3368 false);
3369 boolean requireVoiceVtProvisioning = c.getBoolean(
3370 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3371
3372 // First check to make sure that the capability requires provisioning.
3373 switch (capability) {
3374 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3375 // intentional fallthrough
3376 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3377 if (requireVoiceVtProvisioning) {
3378 // Voice and Video requires provisioning
3379 return true;
3380 }
3381 break;
3382 }
3383 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3384 if (requireUtProvisioning) {
3385 // UT requires provisioning
3386 return true;
3387 }
3388 break;
3389 }
3390 }
3391 return false;
3392 }
3393
3394 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003395 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003396 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3397 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3398 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003399 enforceReadPrivilegedPermission("getImsProvisioningInt");
3400 final long identity = Binder.clearCallingIdentity();
3401 try {
3402 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003403 int slotId = getSlotIndex(subId);
3404 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3405 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3406 + subId + "' for key:" + key);
3407 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3408 }
3409 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003410 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003411 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3412 + subId + "' for key:" + key);
3413 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003414 } finally {
3415 Binder.restoreCallingIdentity(identity);
3416 }
3417 }
3418
3419 @Override
3420 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003421 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3422 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3423 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003424 enforceReadPrivilegedPermission("getImsProvisioningString");
3425 final long identity = Binder.clearCallingIdentity();
3426 try {
3427 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003428 int slotId = getSlotIndex(subId);
3429 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3430 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3431 + subId + "' for key:" + key);
3432 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3433 }
3434 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003435 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003436 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3437 + subId + "' for key:" + key);
3438 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003439 } finally {
3440 Binder.restoreCallingIdentity(identity);
3441 }
3442 }
3443
3444 @Override
3445 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003446 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3447 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3448 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003449 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3450 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003451 final long identity = Binder.clearCallingIdentity();
3452 try {
3453 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003454 int slotId = getSlotIndex(subId);
3455 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3456 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3457 + subId + "' for key:" + key);
3458 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3459 }
3460 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003461 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003462 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3463 + "' for key:" + key);
3464 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003465 } finally {
3466 Binder.restoreCallingIdentity(identity);
3467 }
3468 }
3469
3470 @Override
3471 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003472 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3473 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3474 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003475 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3476 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003477 final long identity = Binder.clearCallingIdentity();
3478 try {
3479 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003480 int slotId = getSlotIndex(subId);
3481 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3482 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3483 + subId + "' for key:" + key);
3484 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3485 }
3486 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003487 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003488 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3489 + "' for key:" + key);
3490 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003491 } finally {
3492 Binder.restoreCallingIdentity(identity);
3493 }
3494 }
3495
Brad Ebinger35c841c2018-10-01 10:40:55 -07003496 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
3497 int slotId = SubscriptionManager.getSlotIndex(subId);
3498 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003499 throw new IllegalArgumentException("Invalid Subscription Id, subId=" + subId);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003500 }
3501 return slotId;
3502 }
3503
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003504 private int getSlotIndex(int subId) {
3505 int slotId = SubscriptionManager.getSlotIndex(subId);
3506 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3507 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3508 }
3509 return slotId;
3510 }
3511
Wink Saville36469e72014-06-11 15:17:00 -07003512 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07003513 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07003514 */
3515 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003516 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Nathan Harold9042f0b2019-05-21 15:51:27 -07003517 if (getTargetSdk(callingPackage) >= android.os.Build.VERSION_CODES.Q
3518 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
3519 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003520 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3521 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003522
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003523 final long identity = Binder.clearCallingIdentity();
3524 try {
3525 final Phone phone = getPhone(subId);
3526 if (phone != null) {
3527 return phone.getServiceState().getDataNetworkType();
3528 } else {
3529 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3530 }
3531 } finally {
3532 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003533 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003534 }
3535
3536 /**
3537 * Returns the data network type
3538 */
3539 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003540 public int getDataNetworkType(String callingPackage) {
3541 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003542 }
3543
3544 /**
3545 * Returns the data network type for a subId
3546 */
3547 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003548 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003549 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003550 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003551 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3552 }
3553
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003554 final long identity = Binder.clearCallingIdentity();
3555 try {
3556 final Phone phone = getPhone(subId);
3557 if (phone != null) {
3558 return phone.getServiceState().getDataNetworkType();
3559 } else {
3560 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3561 }
3562 } finally {
3563 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003564 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003565 }
3566
3567 /**
Wink Saville36469e72014-06-11 15:17:00 -07003568 * Returns the Voice network type for a subId
3569 */
3570 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003571 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003572 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003573 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003574 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3575 }
3576
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003577 final long identity = Binder.clearCallingIdentity();
3578 try {
3579 final Phone phone = getPhone(subId);
3580 if (phone != null) {
3581 return phone.getServiceState().getVoiceNetworkType();
3582 } else {
3583 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3584 }
3585 } finally {
3586 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003587 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003588 }
3589
3590 /**
3591 * @return true if a ICC card is present
3592 */
3593 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003594 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003595 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3596 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003597 }
3598
3599 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003600 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003601 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003602 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003603 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003604 final long identity = Binder.clearCallingIdentity();
3605 try {
3606 final Phone phone = PhoneFactory.getPhone(slotIndex);
3607 if (phone != null) {
3608 return phone.getIccCard().hasIccCard();
3609 } else {
3610 return false;
3611 }
3612 } finally {
3613 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003614 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003615 }
3616
3617 /**
3618 * Return if the current radio is LTE on CDMA. This
3619 * is a tri-state return value as for a period of time
3620 * the mode may be unknown.
3621 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003622 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003623 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003624 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003625 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003626 @Override
3627 public int getLteOnCdmaMode(String callingPackage) {
3628 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003629 }
3630
Sanket Padawe356d7632015-06-22 14:03:32 -07003631 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003632 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003633 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003634 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003635 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3636 }
3637
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003638 final long identity = Binder.clearCallingIdentity();
3639 try {
3640 final Phone phone = getPhone(subId);
3641 if (phone == null) {
3642 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3643 } else {
3644 return phone.getLteOnCdmaMode();
3645 }
3646 } finally {
3647 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003648 }
Wink Saville36469e72014-06-11 15:17:00 -07003649 }
3650
Wink Saville36469e72014-06-11 15:17:00 -07003651 /**
3652 * {@hide}
3653 * Returns Default subId, 0 in the case of single standby.
3654 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003655 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003656 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003657 }
3658
Shishir Agrawala9f32182016-04-12 12:00:16 -07003659 private int getSlotForDefaultSubscription() {
3660 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3661 }
3662
Wink Savilleb564aae2014-10-23 10:18:09 -07003663 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003664 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003665 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003666
Pengquan Menge92a50d2018-09-21 15:54:48 -07003667 private boolean isActiveSubscription(int subId) {
3668 return mSubscriptionController.isActiveSubId(subId);
3669 }
3670
Ihab Awadf2177b72013-11-25 13:33:23 -08003671 /**
3672 * @see android.telephony.TelephonyManager.WifiCallingChoices
3673 */
3674 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003675 final long identity = Binder.clearCallingIdentity();
3676 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003677 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003678 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3679 getWhenToMakeWifiCallsDefaultPreference());
3680 } finally {
3681 Binder.restoreCallingIdentity(identity);
3682 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003683 }
3684
3685 /**
3686 * @see android.telephony.TelephonyManager.WifiCallingChoices
3687 */
3688 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003689 final long identity = Binder.clearCallingIdentity();
3690 try {
3691 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003692 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003693 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3694 } finally {
3695 Binder.restoreCallingIdentity(identity);
3696 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003697 }
3698
Sailesh Nepald1e68152013-12-12 19:08:02 -08003699 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003700 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003701 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003702 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003703
Jordan Liu4c733742019-02-28 12:03:40 -08003704 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
3705 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
3706 if (phoneId == -1) {
3707 throw new IllegalArgumentException("Given slot index: " + slotIndex
3708 + " does not correspond to an active phone");
3709 }
3710 return PhoneFactory.getPhone(phoneId);
3711 }
3712
Shishir Agrawal566b7612013-10-28 14:41:00 -07003713 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003714 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3715 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003716 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3717 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003718 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08003719 if (DBG) {
3720 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3721 }
3722 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
3723 p2);
3724 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003725
Jordan Liu4c733742019-02-28 12:03:40 -08003726
3727 @Override
3728 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
3729 int slotIndex, String callingPackage, String aid, int p2) {
3730 enforceModifyPermission();
3731 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3732 if (DBG) {
3733 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
3734 }
3735 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3736 callingPackage, aid, p2);
3737 }
3738
3739 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
3740 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003741 final long identity = Binder.clearCallingIdentity();
3742 try {
3743 if (TextUtils.equals(ISDR_AID, aid)) {
3744 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003745 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3746 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003747 if (bestComponent == null
3748 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3749 loge("The calling package is not allowed to access ISD-R.");
3750 throw new SecurityException(
3751 "The calling package is not allowed to access ISD-R.");
3752 }
Derek Tan740e1672017-06-27 14:56:27 -07003753 }
Derek Tan740e1672017-06-27 14:56:27 -07003754
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003755 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08003756 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
3757 null /* workSource */);
3758 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003759 return response;
3760 } finally {
3761 Binder.restoreCallingIdentity(identity);
3762 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003763 }
3764
3765 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003766 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003767 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3768 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08003769 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3770 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
3771 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003772
Jordan Liu4c733742019-02-28 12:03:40 -08003773 @Override
3774 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
3775 enforceModifyPermission();
3776 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
3777 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3778 channel);
3779 }
3780
3781 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003782 final long identity = Binder.clearCallingIdentity();
3783 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003784 if (channel < 0) {
3785 return false;
3786 }
Jordan Liu4c733742019-02-28 12:03:40 -08003787 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
3788 null /* workSource */);
3789 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003790 return success;
3791 } finally {
3792 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003793 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003794 }
3795
3796 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003797 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003798 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003799 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3800 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08003801 if (DBG) {
3802 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3803 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3804 + p3 + " data=" + data);
3805 }
3806 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
3807 command, p1, p2, p3, data);
3808 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003809
Jordan Liu4c733742019-02-28 12:03:40 -08003810 @Override
3811 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
3812 int command, int p1, int p2, int p3, String data) {
3813 enforceModifyPermission();
3814 if (DBG) {
3815 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
3816 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3817 + p3 + " data=" + data);
3818 }
3819 return iccTransmitApduLogicalChannelWithPermission(
3820 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
3821 data);
3822 }
3823
3824 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
3825 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003826 final long identity = Binder.clearCallingIdentity();
3827 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07003828 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003829 return "";
3830 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003831
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003832 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08003833 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
3834 null /* workSource */);
3835 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003836
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003837 // Append the returned status code to the end of the response payload.
3838 String s = Integer.toHexString(
3839 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3840 if (response.payload != null) {
3841 s = IccUtils.bytesToHexString(response.payload) + s;
3842 }
3843 return s;
3844 } finally {
3845 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003846 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003847 }
Jake Hambye994d462014-02-03 13:10:13 -08003848
Evan Charltonc66da362014-05-16 14:06:40 -07003849 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003850 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3851 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003852 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3853 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003854 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08003855 if (DBG) {
3856 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3857 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3858 }
3859 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
3860 cla, command, p1, p2, p3, data);
3861 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003862
Jordan Liu4c733742019-02-28 12:03:40 -08003863 @Override
3864 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
3865 int command, int p1, int p2, int p3, String data) {
3866 enforceModifyPermission();
3867 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3868 if (DBG) {
3869 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
3870 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
3871 + " data=" + data);
3872 }
3873
3874 return iccTransmitApduBasicChannelWithPermission(
3875 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
3876 p2, p3, data);
3877 }
3878
3879 // open APDU basic channel assuming the caller has sufficient permissions
3880 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
3881 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003882 final long identity = Binder.clearCallingIdentity();
3883 try {
3884 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3885 && TextUtils.equals(ISDR_AID, data)) {
3886 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003887 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3888 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003889 if (bestComponent == null
3890 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3891 loge("The calling package is not allowed to select ISD-R.");
3892 throw new SecurityException(
3893 "The calling package is not allowed to select ISD-R.");
3894 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003895 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003896
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003897 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08003898 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
3899 null /* workSource */);
3900 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003901
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003902 // Append the returned status code to the end of the response payload.
3903 String s = Integer.toHexString(
3904 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3905 if (response.payload != null) {
3906 s = IccUtils.bytesToHexString(response.payload) + s;
3907 }
3908 return s;
3909 } finally {
3910 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003911 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003912 }
3913
3914 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003915 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003916 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003917 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3918 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003919
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003920 final long identity = Binder.clearCallingIdentity();
3921 try {
3922 if (DBG) {
3923 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3924 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3925 }
3926
3927 IccIoResult response =
3928 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3929 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3930 subId);
3931
3932 if (DBG) {
3933 log("Exchange SIM_IO [R]" + response);
3934 }
3935
3936 byte[] result = null;
3937 int length = 2;
3938 if (response.payload != null) {
3939 length = 2 + response.payload.length;
3940 result = new byte[length];
3941 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3942 } else {
3943 result = new byte[length];
3944 }
3945
3946 result[length - 1] = (byte) response.sw2;
3947 result[length - 2] = (byte) response.sw1;
3948 return result;
3949 } finally {
3950 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003951 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003952 }
3953
Nathan Haroldb3014052017-01-25 15:57:32 -08003954 /**
3955 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3956 * on a particular subscription
3957 */
sqianb6e41952018-03-12 14:54:01 -07003958 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3959 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3960 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3961 return null;
3962 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003963
3964 final long identity = Binder.clearCallingIdentity();
3965 try {
3966 if (appType != TelephonyManager.APPTYPE_USIM
3967 && appType != TelephonyManager.APPTYPE_SIM) {
3968 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3969 return null;
3970 }
3971 Object response = sendRequest(
3972 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3973 if (response instanceof String[]) {
3974 return (String[]) response;
3975 }
3976 // Response is an Exception of some kind,
3977 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003978 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003979 } finally {
3980 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003981 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003982 }
3983
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003984 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003985 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003986 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3987 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003988
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003989 final long identity = Binder.clearCallingIdentity();
3990 try {
3991 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3992 if (response.payload == null) {
3993 return "";
3994 }
Evan Charltonc66da362014-05-16 14:06:40 -07003995
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003996 // Append the returned status code to the end of the response payload.
3997 String s = Integer.toHexString(
3998 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3999 s = IccUtils.bytesToHexString(response.payload) + s;
4000 return s;
4001 } finally {
4002 Binder.restoreCallingIdentity(identity);
4003 }
Evan Charltonc66da362014-05-16 14:06:40 -07004004 }
4005
Jake Hambye994d462014-02-03 13:10:13 -08004006 /**
4007 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4008 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4009 *
4010 * @param itemID the ID of the item to read
4011 * @return the NV item as a String, or null on error.
4012 */
4013 @Override
4014 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004015 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004016 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4017 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004018
4019 final long identity = Binder.clearCallingIdentity();
4020 try {
4021 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004022 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004023 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4024 return value;
4025 } finally {
4026 Binder.restoreCallingIdentity(identity);
4027 }
Jake Hambye994d462014-02-03 13:10:13 -08004028 }
4029
4030 /**
4031 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4032 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4033 *
4034 * @param itemID the ID of the item to read
4035 * @param itemValue the value to write, as a String
4036 * @return true on success; false on any failure
4037 */
4038 @Override
4039 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004040 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004041 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4042 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004043
4044 final long identity = Binder.clearCallingIdentity();
4045 try {
4046 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4047 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004048 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004049 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4050 return success;
4051 } finally {
4052 Binder.restoreCallingIdentity(identity);
4053 }
Jake Hambye994d462014-02-03 13:10:13 -08004054 }
4055
4056 /**
4057 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4058 * Used for device configuration by some CDMA operators.
4059 *
4060 * @param preferredRoamingList byte array containing the new PRL
4061 * @return true on success; false on any failure
4062 */
4063 @Override
4064 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004065 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4066 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004067
4068 final long identity = Binder.clearCallingIdentity();
4069 try {
4070 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4071 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4072 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4073 return success;
4074 } finally {
4075 Binder.restoreCallingIdentity(identity);
4076 }
Jake Hambye994d462014-02-03 13:10:13 -08004077 }
4078
4079 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004080 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004081 * Used for device configuration by some CDMA operators.
4082 *
chen xu6dac5ab2018-10-26 17:39:23 -07004083 * @param slotIndex - device slot.
4084 *
Jake Hambye994d462014-02-03 13:10:13 -08004085 * @return true on success; false on any failure
4086 */
4087 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004088 public boolean resetModemConfig(int slotIndex) {
4089 Phone phone = PhoneFactory.getPhone(slotIndex);
4090 if (phone != null) {
4091 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4092 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004093
chen xu6dac5ab2018-10-26 17:39:23 -07004094 final long identity = Binder.clearCallingIdentity();
4095 try {
4096 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4097 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4098 return success;
4099 } finally {
4100 Binder.restoreCallingIdentity(identity);
4101 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004102 }
chen xu6dac5ab2018-10-26 17:39:23 -07004103 return false;
4104 }
4105
4106 /**
4107 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4108 *
4109 * @param slotIndex - device slot.
4110 *
4111 * @return true on success; false on any failure
4112 */
4113 @Override
4114 public boolean rebootModem(int slotIndex) {
4115 Phone phone = PhoneFactory.getPhone(slotIndex);
4116 if (phone != null) {
4117 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4118 mApp, phone.getSubId(), "rebootModem");
4119
4120 final long identity = Binder.clearCallingIdentity();
4121 try {
4122 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4123 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4124 return success;
4125 } finally {
4126 Binder.restoreCallingIdentity(identity);
4127 }
4128 }
4129 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004130 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004131
Svet Ganovb320e182015-04-16 12:30:10 -07004132 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004133 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004134 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004135 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004136 return new String[0];
4137 }
4138
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004139 final long identity = Binder.clearCallingIdentity();
4140 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004141 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004142 } finally {
4143 Binder.restoreCallingIdentity(identity);
4144 }
Wink Saville36469e72014-06-11 15:17:00 -07004145 }
4146
Brad Ebinger51f743a2017-01-23 13:50:20 -08004147 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004148 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4149 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004150 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004151 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004152 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004153
4154 final long identity = Binder.clearCallingIdentity();
4155 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004156 ImsResolver resolver = PhoneFactory.getImsResolver();
4157 if (resolver == null) {
4158 // may happen if the device does not support IMS.
4159 return;
4160 }
4161 resolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004162 } finally {
4163 Binder.restoreCallingIdentity(identity);
4164 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004165 }
4166
4167 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004168 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4169 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004170 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004171 public void disableIms(int slotId) {
4172 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004173
4174 final long identity = Binder.clearCallingIdentity();
4175 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004176 ImsResolver resolver = PhoneFactory.getImsResolver();
4177 if (resolver == null) {
4178 // may happen if the device does not support IMS.
4179 return;
4180 }
4181 resolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004182 } finally {
4183 Binder.restoreCallingIdentity(identity);
4184 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004185 }
4186
4187 /**
4188 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4189 * feature or {@link null} if the service is not available. If the feature is available, the
4190 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4191 */
4192 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004193 IImsServiceFeatureCallback callback) {
4194 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004195
4196 final long identity = Binder.clearCallingIdentity();
4197 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004198 ImsResolver resolver = PhoneFactory.getImsResolver();
4199 if (resolver == null) {
4200 // may happen if the device does not support IMS.
4201 return null;
4202 }
4203 return resolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004204 } finally {
4205 Binder.restoreCallingIdentity(identity);
4206 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004207 }
4208
4209 /**
4210 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4211 * feature during emergency calling or {@link null} if the service is not available. If the
4212 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4213 * listener for feature updates.
4214 */
4215 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4216 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004217
4218 final long identity = Binder.clearCallingIdentity();
4219 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004220 ImsResolver resolver = PhoneFactory.getImsResolver();
4221 if (resolver == null) {
4222 // may happen if the device does not support IMS.
4223 return null;
4224 }
4225 return resolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004226 } finally {
4227 Binder.restoreCallingIdentity(identity);
4228 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004229 }
4230
Brad Ebinger5f64b052017-12-14 14:26:15 -08004231 /**
4232 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004233 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004234 */
4235 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4236 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004237
4238 final long identity = Binder.clearCallingIdentity();
4239 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004240 ImsResolver resolver = PhoneFactory.getImsResolver();
4241 if (resolver == null) {
4242 // may happen if the device does not support IMS.
4243 return null;
4244 }
4245 return resolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004246 } finally {
4247 Binder.restoreCallingIdentity(identity);
4248 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004249 }
4250
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004251 /**
4252 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004253 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004254 */
4255 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4256 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004257
4258 final long identity = Binder.clearCallingIdentity();
4259 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004260 ImsResolver resolver = PhoneFactory.getImsResolver();
4261 if (resolver == null) {
4262 // may happen if the device does not support IMS.
4263 return null;
4264 }
4265 return resolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004266 } finally {
4267 Binder.restoreCallingIdentity(identity);
4268 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004269 }
4270
Brad Ebinger884c07b2018-02-15 16:17:40 -08004271 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004272 * Sets the ImsService Package Name that Telephony will bind to.
4273 *
4274 * @param slotId the slot ID that the ImsService should bind for.
4275 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4276 * ImsService is the device default ImsService.
4277 * @param packageName The package name of the application that contains the ImsService to bind
4278 * to.
4279 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4280 * @hide
4281 */
4282 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004283 int[] subIds = SubscriptionManager.getSubId(slotId);
4284 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4285 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4286 "setImsService");
4287
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004288 final long identity = Binder.clearCallingIdentity();
4289 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004290 ImsResolver resolver = PhoneFactory.getImsResolver();
4291 if (resolver == null) {
4292 // may happen if the device does not support IMS.
4293 return false;
4294 }
4295 return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService,
4296 packageName);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004297 } finally {
4298 Binder.restoreCallingIdentity(identity);
4299 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004300 }
4301
4302 /**
4303 * Return the ImsService configuration.
4304 *
4305 * @param slotId The slot that the ImsService is associated with.
4306 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4307 * the device default.
4308 * @return the package name of the ImsService configuration.
4309 */
4310 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004311 int[] subIds = SubscriptionManager.getSubId(slotId);
4312 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4313 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4314 "getImsService");
4315
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004316 final long identity = Binder.clearCallingIdentity();
4317 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004318 ImsResolver resolver = PhoneFactory.getImsResolver();
4319 if (resolver == null) {
4320 // may happen if the device does not support IMS.
4321 return "";
4322 }
4323 return resolver.getImsServiceConfiguration(slotId, isCarrierImsService);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004324 } finally {
4325 Binder.restoreCallingIdentity(identity);
4326 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004327 }
4328
Wink Saville36469e72014-06-11 15:17:00 -07004329 public void setImsRegistrationState(boolean registered) {
4330 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004331
4332 final long identity = Binder.clearCallingIdentity();
4333 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004334 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004335 } finally {
4336 Binder.restoreCallingIdentity(identity);
4337 }
Wink Saville36469e72014-06-11 15:17:00 -07004338 }
4339
4340 /**
Stuart Scott54788802015-03-30 13:18:01 -07004341 * Set the network selection mode to automatic.
4342 *
4343 */
4344 @Override
4345 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004346 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4347 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004348
Pengquan Menge92a50d2018-09-21 15:54:48 -07004349 if (!isActiveSubscription(subId)) {
4350 return;
4351 }
4352
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004353 final long identity = Binder.clearCallingIdentity();
4354 try {
4355 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4356 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4357 } finally {
4358 Binder.restoreCallingIdentity(identity);
4359 }
Stuart Scott54788802015-03-30 13:18:01 -07004360 }
4361
Pengquan Mengea84e042018-09-20 14:57:26 -07004362 /**
4363 * Ask the radio to connect to the input network and change selection mode to manual.
4364 *
4365 * @param subId the id of the subscription.
4366 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4367 * the operator to attach to.
4368 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4369 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4370 * normal network selection next time.
4371 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004372 */
4373 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004374 public boolean setNetworkSelectionModeManual(
4375 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004376 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4377 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004378
4379 if (!isActiveSubscription(subId)) {
4380 return false;
4381 }
4382
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004383 final long identity = Binder.clearCallingIdentity();
4384 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004385 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004386 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004387 if (DBG) {
4388 log("setNetworkSelectionModeManual: subId: " + subId
4389 + " operator: " + operatorInfo);
4390 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004391 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4392 } finally {
4393 Binder.restoreCallingIdentity(identity);
4394 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004395 }
4396
4397 /**
4398 * Scans for available networks.
4399 */
4400 @Override
Hall Liuf19c44f2018-11-27 14:38:17 -08004401 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004402 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4403 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004404 LocationAccessPolicy.LocationPermissionResult locationResult =
4405 LocationAccessPolicy.checkLocationPermission(mApp,
4406 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4407 .setCallingPackage(callingPackage)
4408 .setCallingPid(Binder.getCallingPid())
4409 .setCallingUid(Binder.getCallingUid())
4410 .setMethod("getCellNetworkScanResults")
4411 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4412 .build());
4413 switch (locationResult) {
4414 case DENIED_HARD:
4415 throw new SecurityException("Not allowed to access scan results -- location");
4416 case DENIED_SOFT:
4417 return null;
4418 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004419
Pengquan Menga1bb6272018-09-06 09:59:22 -07004420 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004421 try {
4422 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004423 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004424 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004425 } finally {
4426 Binder.restoreCallingIdentity(identity);
4427 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004428 }
4429
4430 /**
yinxub1bed742017-04-17 11:45:04 -07004431 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004432 *
yinxub1bed742017-04-17 11:45:04 -07004433 * @param subId id of the subscription
4434 * @param request contains the radio access networks with bands/channels to scan
4435 * @param messenger callback messenger for scan results or errors
4436 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004437 * @return the id of the requested scan which can be used to stop the scan.
4438 */
4439 @Override
4440 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Hall Liuf19c44f2018-11-27 14:38:17 -08004441 IBinder binder, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004442 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4443 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004444 LocationAccessPolicy.LocationPermissionResult locationResult =
4445 LocationAccessPolicy.checkLocationPermission(mApp,
4446 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4447 .setCallingPackage(callingPackage)
4448 .setCallingPid(Binder.getCallingPid())
4449 .setCallingUid(Binder.getCallingUid())
4450 .setMethod("requestNetworkScan")
4451 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4452 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004453 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07004454 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08004455 if (e != null) {
4456 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4457 throw e;
4458 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07004459 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004460 return TelephonyScanManager.INVALID_SCAN_ID;
4461 }
4462 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004463 }
Hall Liu912dfd32019-04-25 14:02:26 -07004464 int callingUid = Binder.getCallingUid();
4465 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07004466 final long identity = Binder.clearCallingIdentity();
4467 try {
4468 return mNetworkScanRequestTracker.startNetworkScan(
4469 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07004470 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07004471 } finally {
4472 Binder.restoreCallingIdentity(identity);
4473 }
yinxu504e1392017-04-12 16:03:22 -07004474 }
4475
Hall Liub2ac8ef2019-02-28 15:56:23 -08004476 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07004477 NetworkScanRequest request, int subId) {
4478 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
4479 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
4480 boolean hasNetworkScanPermission =
4481 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4482 == PERMISSION_GRANTED;
4483
4484 if (!hasCarrierPriv && !hasNetworkScanPermission) {
4485 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
4486 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08004487 }
4488
4489 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4490 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004491 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4492 return new SecurityException("Specific channels must not be"
4493 + " scanned without location access.");
4494 }
4495 }
4496 }
4497
Hall Liub2ac8ef2019-02-28 15:56:23 -08004498 return null;
4499 }
4500
yinxu504e1392017-04-12 16:03:22 -07004501 /**
4502 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004503 *
4504 * @param subId id of the subscription
4505 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004506 */
4507 @Override
4508 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004509 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4510 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004511
Hall Liu912dfd32019-04-25 14:02:26 -07004512 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004513 final long identity = Binder.clearCallingIdentity();
4514 try {
Hall Liu912dfd32019-04-25 14:02:26 -07004515 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004516 } finally {
4517 Binder.restoreCallingIdentity(identity);
4518 }
yinxu504e1392017-04-12 16:03:22 -07004519 }
4520
4521 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004522 * Get the calculated preferred network type.
4523 * Used for debugging incorrect network type.
4524 *
4525 * @return the preferred network type, defined in RILConstants.java.
4526 */
4527 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004528 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004529 final Phone defaultPhone = getDefaultPhone();
4530 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4531 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004532 return RILConstants.PREFERRED_NETWORK_MODE;
4533 }
4534
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004535 final long identity = Binder.clearCallingIdentity();
4536 try {
4537 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004538 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004539 } finally {
4540 Binder.restoreCallingIdentity(identity);
4541 }
Junda Liu84d15a22014-07-02 11:21:04 -07004542 }
4543
4544 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004545 * Get the preferred network type.
4546 * Used for device configuration by some CDMA operators.
4547 *
4548 * @return the preferred network type, defined in RILConstants.java.
4549 */
4550 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004551 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08004552 TelephonyPermissions
4553 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4554 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004555
4556 final long identity = Binder.clearCallingIdentity();
4557 try {
4558 if (DBG) log("getPreferredNetworkType");
4559 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4560 int networkType = (result != null ? result[0] : -1);
4561 if (DBG) log("getPreferredNetworkType: " + networkType);
4562 return networkType;
4563 } finally {
4564 Binder.restoreCallingIdentity(identity);
4565 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004566 }
4567
4568 /**
4569 * Set the preferred network type.
4570 * Used for device configuration by some CDMA operators.
4571 *
4572 * @param networkType the preferred network type, defined in RILConstants.java.
4573 * @return true on success; false on any failure.
4574 */
4575 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004576 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004577 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4578 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004579
4580 final long identity = Binder.clearCallingIdentity();
4581 try {
4582 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4583 Boolean success = (Boolean) sendRequest(
4584 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4585 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4586 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004587 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004588 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4589 }
4590 return success;
4591 } finally {
4592 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004593 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004594 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004595
4596 /**
Miaoa84611c2019-03-15 09:21:10 +08004597 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004598 *
Miaoa84611c2019-03-15 09:21:10 +08004599 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004600 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004601 * @hide
4602 */
4603 @Override
Miaoa84611c2019-03-15 09:21:10 +08004604 public boolean getTetherApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004605 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004606 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08004607 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004608 try {
Miaoa84611c2019-03-15 09:21:10 +08004609 if (phone != null) {
4610 return phone.hasMatchedTetherApnSetting();
4611 } else {
4612 return false;
4613 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004614 } finally {
4615 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004616 }
Junda Liu475951f2014-11-07 16:45:03 -08004617 }
4618
4619 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004620 * Set mobile data enabled
4621 * Used by the user through settings etc to turn on/off mobile data
4622 *
4623 * @param enable {@code true} turn turn data on, else {@code false}
4624 */
4625 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004626 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004627 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4628 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004629
4630 final long identity = Binder.clearCallingIdentity();
4631 try {
4632 int phoneId = mSubscriptionController.getPhoneId(subId);
4633 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4634 Phone phone = PhoneFactory.getPhone(phoneId);
4635 if (phone != null) {
4636 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08004637 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004638 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004639 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004640 }
4641 } finally {
4642 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004643 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004644 }
4645
4646 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004647 * Get the user enabled state of Mobile Data.
4648 *
4649 * TODO: remove and use isUserDataEnabled.
4650 * This can't be removed now because some vendor codes
4651 * calls through ITelephony directly while they should
4652 * use TelephonyManager.
4653 *
4654 * @return true on enabled
4655 */
4656 @Override
4657 public boolean getDataEnabled(int subId) {
4658 return isUserDataEnabled(subId);
4659 }
4660
4661 /**
4662 * Get whether mobile data is enabled per user setting.
4663 *
4664 * There are other factors deciding whether mobile data is actually enabled, but they are
4665 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004666 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004667 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004668 *
4669 * @return {@code true} if data is enabled else {@code false}
4670 */
4671 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004672 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004673 try {
4674 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4675 null);
4676 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004677 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4678 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004679 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004680
4681 final long identity = Binder.clearCallingIdentity();
4682 try {
4683 int phoneId = mSubscriptionController.getPhoneId(subId);
4684 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4685 Phone phone = PhoneFactory.getPhone(phoneId);
4686 if (phone != null) {
4687 boolean retVal = phone.isUserDataEnabled();
4688 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4689 return retVal;
4690 } else {
4691 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4692 return false;
4693 }
4694 } finally {
4695 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004696 }
4697 }
4698
4699 /**
4700 * Get whether mobile data is enabled.
4701 *
4702 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4703 * whether mobile data is actually enabled.
4704 *
4705 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4706 *
4707 * @return {@code true} if data is enabled else {@code false}
4708 */
4709 @Override
4710 public boolean isDataEnabled(int subId) {
4711 try {
4712 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4713 null);
4714 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004715 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4716 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004717 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004718
4719 final long identity = Binder.clearCallingIdentity();
4720 try {
4721 int phoneId = mSubscriptionController.getPhoneId(subId);
4722 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4723 Phone phone = PhoneFactory.getPhone(phoneId);
4724 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08004725 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004726 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4727 return retVal;
4728 } else {
4729 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4730 return false;
4731 }
4732 } finally {
4733 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004734 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004735 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004736
4737 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004738 public int getCarrierPrivilegeStatus(int subId) {
4739 final Phone phone = getPhone(subId);
4740 if (phone == null) {
4741 loge("getCarrierPrivilegeStatus: Invalid subId");
4742 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4743 }
4744 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004745 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004746 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004747 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4748 }
4749 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004750 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004751 }
Junda Liu29340342014-07-10 15:23:27 -07004752
4753 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004754 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4755 final Phone phone = getPhone(subId);
4756 if (phone == null) {
4757 loge("getCarrierPrivilegeStatus: Invalid subId");
4758 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4759 }
4760 UiccProfile profile =
4761 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4762 if (profile == null) {
4763 loge("getCarrierPrivilegeStatus: No UICC");
4764 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4765 }
4766 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4767 }
4768
4769 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07004770 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
4771 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08004772 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07004773 }
4774
4775 int phoneId = SubscriptionManager.getPhoneId(subId);
4776 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004777 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07004778 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004779 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4780 }
chen xuf7e9fe82019-05-09 19:31:02 -07004781
4782 return card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004783 }
4784
4785 @Override
4786 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004787 if (TextUtils.isEmpty(pkgName))
4788 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004789 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4790 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4791 UiccCard card = UiccController.getInstance().getUiccCard(i);
4792 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004793 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004794 continue;
4795 }
4796
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004797 result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004798 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4799 break;
4800 }
4801 }
4802
4803 return result;
Junda Liu29340342014-07-10 15:23:27 -07004804 }
Derek Tan89e89d42014-07-08 17:00:10 -07004805
4806 @Override
Junda Liue64de782015-04-16 17:19:16 -07004807 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4808 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4809 loge("phoneId " + phoneId + " is not valid.");
4810 return null;
4811 }
4812 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004813 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004814 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004815 return null ;
4816 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004817 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004818 }
4819
Amith Yamasani6e118872016-02-19 12:53:51 -08004820 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07004821 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004822 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08004823 List<String> privilegedPackages = new ArrayList<>();
4824 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07004825 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
4826 // has UICC in that slot.
4827 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08004828 if (card.hasCarrierPrivilegeRules()) {
4829 if (packages == null) {
4830 // Only check packages in user 0 for now
4831 packages = pm.getInstalledPackagesAsUser(
4832 PackageManager.MATCH_DISABLED_COMPONENTS
chen xuf7e9fe82019-05-09 19:31:02 -07004833 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4834 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08004835 }
4836 for (int p = packages.size() - 1; p >= 0; p--) {
4837 PackageInfo pkgInfo = packages.get(p);
4838 if (pkgInfo != null && pkgInfo.packageName != null
4839 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07004840 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08004841 privilegedPackages.add(pkgInfo.packageName);
4842 }
4843 }
4844 }
4845 }
4846 return privilegedPackages;
4847 }
4848
chen xuf7e9fe82019-05-09 19:31:02 -07004849 @Override
4850 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
4851 List<String> privilegedPackages = new ArrayList<>();
4852 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4853 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
4854 }
4855 return privilegedPackages;
4856 }
4857
Wink Savilleb564aae2014-10-23 10:18:09 -07004858 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004859 final Phone phone = getPhone(subId);
4860 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004861 if (card == null) {
4862 loge("getIccId: No UICC");
4863 return null;
4864 }
4865 String iccId = card.getIccId();
4866 if (TextUtils.isEmpty(iccId)) {
4867 loge("getIccId: ICC ID is null or empty.");
4868 return null;
4869 }
4870 return iccId;
4871 }
4872
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004873 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004874 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4875 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004876 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4877 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004878
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004879 final long identity = Binder.clearCallingIdentity();
4880 try {
4881 final String iccId = getIccId(subId);
4882 final Phone phone = getPhone(subId);
4883 if (phone == null) {
4884 return false;
4885 }
4886 final String subscriberId = phone.getSubscriberId();
4887
4888 if (DBG_MERGE) {
4889 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4890 + subscriberId + " to " + number);
4891 }
4892
4893 if (TextUtils.isEmpty(iccId)) {
4894 return false;
4895 }
4896
4897 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4898
4899 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4900 if (alphaTag == null) {
4901 editor.remove(alphaTagPrefKey);
4902 } else {
4903 editor.putString(alphaTagPrefKey, alphaTag);
4904 }
4905
4906 // Record both the line number and IMSI for this ICCID, since we need to
4907 // track all merged IMSIs based on line number
4908 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4909 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4910 if (number == null) {
4911 editor.remove(numberPrefKey);
4912 editor.remove(subscriberPrefKey);
4913 } else {
4914 editor.putString(numberPrefKey, number);
4915 editor.putString(subscriberPrefKey, subscriberId);
4916 }
4917
4918 editor.commit();
4919 return true;
4920 } finally {
4921 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004922 }
Derek Tan7226c842014-07-02 17:42:23 -07004923 }
4924
4925 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004926 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004927 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004928 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004929 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004930 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004931 return null;
4932 }
Derek Tan97ebb422014-09-05 16:55:38 -07004933
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004934 final long identity = Binder.clearCallingIdentity();
4935 try {
4936 String iccId = getIccId(subId);
4937 if (iccId != null) {
4938 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4939 if (DBG_MERGE) {
4940 log("getLine1NumberForDisplay returning "
4941 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4942 }
4943 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004944 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004945 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4946 return null;
4947 } finally {
4948 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004949 }
Derek Tan7226c842014-07-02 17:42:23 -07004950 }
4951
4952 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004953 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004954 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004955 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004956 return null;
4957 }
Derek Tan97ebb422014-09-05 16:55:38 -07004958
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004959 final long identity = Binder.clearCallingIdentity();
4960 try {
4961 String iccId = getIccId(subId);
4962 if (iccId != null) {
4963 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4964 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4965 }
4966 return null;
4967 } finally {
4968 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004969 }
Derek Tan7226c842014-07-02 17:42:23 -07004970 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004971
4972 @Override
Jordan Liub49b04b2019-05-06 14:45:15 -07004973 public String[] getMergedSubscriberIds(int subId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004974 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4975 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004976 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004977 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4978 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004979 return null;
4980 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004981
Jordan Liub49b04b2019-05-06 14:45:15 -07004982 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4983 // the process, where TelephonyManager was instantiated.
4984 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004985 final long identity = Binder.clearCallingIdentity();
4986 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004987 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004988 final TelephonyManager tele = TelephonyManager.from(context);
4989 final SubscriptionManager sub = SubscriptionManager.from(context);
4990
4991 // Figure out what subscribers are currently active
4992 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004993
Jordan Liub49b04b2019-05-06 14:45:15 -07004994 // Only consider subs which match the current subId
4995 // This logic can be simplified. See b/131189269 for progress.
4996 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004997 activeSubscriberIds.add(tele.getSubscriberId(subId));
4998 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004999
5000 // First pass, find a number override for an active subscriber
5001 String mergeNumber = null;
5002 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5003 for (String key : prefs.keySet()) {
5004 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5005 final String subscriberId = (String) prefs.get(key);
5006 if (activeSubscriberIds.contains(subscriberId)) {
5007 final String iccId = key.substring(
5008 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5009 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5010 mergeNumber = (String) prefs.get(numberKey);
5011 if (DBG_MERGE) {
5012 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5013 + " for active subscriber " + subscriberId);
5014 }
5015 if (!TextUtils.isEmpty(mergeNumber)) {
5016 break;
5017 }
5018 }
5019 }
5020 }
5021
5022 // Shortcut when no active merged subscribers
5023 if (TextUtils.isEmpty(mergeNumber)) {
5024 return null;
5025 }
5026
5027 // Second pass, find all subscribers under that line override
5028 final ArraySet<String> result = new ArraySet<>();
5029 for (String key : prefs.keySet()) {
5030 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5031 final String number = (String) prefs.get(key);
5032 if (mergeNumber.equals(number)) {
5033 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5034 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5035 final String subscriberId = (String) prefs.get(subscriberKey);
5036 if (!TextUtils.isEmpty(subscriberId)) {
5037 result.add(subscriberId);
5038 }
5039 }
5040 }
5041 }
5042
5043 final String[] resultArray = result.toArray(new String[result.size()]);
5044 Arrays.sort(resultArray);
5045 if (DBG_MERGE) {
5046 Slog.d(LOG_TAG,
5047 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5048 }
5049 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005050 } finally {
5051 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005052 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005053 }
5054
5055 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005056 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005057 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5058 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005059
5060 final long identity = Binder.clearCallingIdentity();
5061 try {
5062 final Phone phone = getPhone(subId);
5063 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5064 } finally {
5065 Binder.restoreCallingIdentity(identity);
5066 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005067 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005068
5069 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005070 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005071 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5072 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005073 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005074
5075 final long identity = Binder.clearCallingIdentity();
5076 try {
5077 final Phone phone = getPhone(subId);
5078 if (phone == null) {
5079 return false;
5080 }
5081 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5082 cdmaNonRoamingList);
5083 } finally {
5084 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005085 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005086 }
5087
5088 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005089 @Deprecated
5090 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5091 enforceModifyPermission();
5092
5093 int returnValue = 0;
5094 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005095 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005096 if(result.exception == null) {
5097 if (result.result != null) {
5098 byte[] responseData = (byte[])(result.result);
5099 if(responseData.length > oemResp.length) {
5100 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5101 responseData.length + "bytes. Buffer Size is " +
5102 oemResp.length + "bytes.");
5103 }
5104 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5105 returnValue = responseData.length;
5106 }
5107 } else {
5108 CommandException ex = (CommandException) result.exception;
5109 returnValue = ex.getCommandError().ordinal();
5110 if(returnValue > 0) returnValue *= -1;
5111 }
5112 } catch (RuntimeException e) {
5113 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5114 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5115 if(returnValue > 0) returnValue *= -1;
5116 }
5117
5118 return returnValue;
5119 }
5120
5121 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005122 public void setRadioCapability(RadioAccessFamily[] rafs) {
5123 try {
5124 ProxyController.getInstance().setRadioCapability(rafs);
5125 } catch (RuntimeException e) {
5126 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5127 }
5128 }
5129
5130 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005131 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005132 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005133 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005134 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005135 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005136 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005137 final long identity = Binder.clearCallingIdentity();
5138 try {
chen xub97461a2018-10-26 14:17:57 -07005139 TelephonyPermissions
5140 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5141 mApp, phone.getSubId(), "getRadioAccessFamily");
5142 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005143 } finally {
5144 Binder.restoreCallingIdentity(identity);
5145 }
chen xub97461a2018-10-26 14:17:57 -07005146 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005147 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005148
5149 @Override
5150 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005151 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005152 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005153
5154 final long identity = Binder.clearCallingIdentity();
5155 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005156 ImsManager.getInstance(defaultPhone.getContext(),
5157 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005158 } finally {
5159 Binder.restoreCallingIdentity(identity);
5160 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005161 }
5162
5163 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005164 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005165 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00005166 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005167 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005168 return false;
5169 }
Svet Ganovb320e182015-04-16 12:30:10 -07005170
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005171 final long identity = Binder.clearCallingIdentity();
5172 try {
5173 // Check the user preference and the system-level IMS setting. Even if the user has
5174 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5175 // In the long run, we may instead need to check if there exists a connection service
5176 // which can support video calling.
5177 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005178 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005179 return imsManager.isVtEnabledByPlatform()
5180 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5181 && imsManager.isVtEnabledByUser();
5182 } finally {
5183 Binder.restoreCallingIdentity(identity);
5184 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005185 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005186
Andrew Leea1239f22015-03-02 17:44:07 -08005187 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005188 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
5189 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5190 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5191 return false;
5192 }
5193
5194 final long identity = Binder.clearCallingIdentity();
5195 try {
5196 CarrierConfigManager configManager =
5197 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005198 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005199 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5200 } finally {
5201 Binder.restoreCallingIdentity(identity);
5202 }
Andrew Leea1239f22015-03-02 17:44:07 -08005203 }
5204
5205 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005206 public boolean isWorldPhone(int subId, String callingPackage) {
5207 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5208 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5209 return false;
5210 }
5211
5212 final long identity = Binder.clearCallingIdentity();
5213 try {
5214 CarrierConfigManager configManager =
5215 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005216 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005217 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5218 } finally {
5219 Binder.restoreCallingIdentity(identity);
5220 }
Andrew Leea1239f22015-03-02 17:44:07 -08005221 }
5222
Andrew Lee9431b832015-03-09 18:46:45 -07005223 @Override
5224 public boolean isTtyModeSupported() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005225 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005226 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005227 }
5228
5229 @Override
5230 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005231 final long identity = Binder.clearCallingIdentity();
5232 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005233 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005234 } finally {
5235 Binder.restoreCallingIdentity(identity);
5236 }
Andrew Lee9431b832015-03-09 18:46:45 -07005237 }
5238
Hall Liuf6668912018-10-31 17:05:23 -07005239 /**
5240 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5241 * support for the feature and device firmware support.
5242 *
5243 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5244 */
5245 @Override
5246 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005247 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005248 final Phone phone = getPhone(subscriptionId);
5249 if (phone == null) {
5250 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5251 return false;
5252 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005253 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005254 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005255 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5256 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005257 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005258 return isCarrierSupported && isDeviceSupported;
5259 } finally {
5260 Binder.restoreCallingIdentity(identity);
5261 }
Hall Liu98187582018-01-22 19:15:32 -08005262 }
5263
Hall Liuf6668912018-10-31 17:05:23 -07005264 /**
5265 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
5266 * both also support RTT.
5267 */
5268 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005269 final long identity = Binder.clearCallingIdentity();
5270 try {
Hall Liuf6668912018-10-31 17:05:23 -07005271 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005272 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005273 } finally {
5274 Binder.restoreCallingIdentity(identity);
5275 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005276 }
5277
Sanket Padawe7310cc72015-01-14 09:53:20 -08005278 /**
5279 * Returns the unique device ID of phone, for example, the IMEI for
5280 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5281 *
5282 * <p>Requires Permission:
5283 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5284 */
5285 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005286 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005287 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005288 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005289 return null;
5290 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005291 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005292 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
5293 callingPackage, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005294 return null;
5295 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005296
5297 final long identity = Binder.clearCallingIdentity();
5298 try {
5299 return phone.getDeviceId();
5300 } finally {
5301 Binder.restoreCallingIdentity(identity);
5302 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005303 }
5304
Ping Sunc67b7c22016-03-02 19:16:45 +08005305 /**
5306 * {@hide}
5307 * Returns the IMS Registration Status on a particular subid
5308 *
5309 * @param subId
5310 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005311 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005312 Phone phone = getPhone(subId);
5313 if (phone != null) {
5314 return phone.isImsRegistered();
5315 } else {
5316 return false;
5317 }
5318 }
5319
Santos Cordon7a1885b2015-02-03 11:15:19 -08005320 @Override
5321 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005322 final long identity = Binder.clearCallingIdentity();
5323 try {
5324 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5325 } finally {
5326 Binder.restoreCallingIdentity(identity);
5327 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005328 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005329
Tyler Gunnf70ed162019-04-03 15:28:53 -07005330 @Override
5331 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5332 final long identity = Binder.clearCallingIdentity();
5333 try {
5334 Phone phone = getPhone(subscriptionId);
5335 if (phone == null) {
5336 return null;
5337 }
5338 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5339 } finally {
5340 Binder.restoreCallingIdentity(identity);
5341 }
5342 }
5343
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005344 /**
5345 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005346 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005347 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005348 final long identity = Binder.clearCallingIdentity();
5349 try {
5350 Phone phone = getPhone(subId);
5351 if (phone != null) {
5352 return phone.isWifiCallingEnabled();
5353 } else {
5354 return false;
5355 }
5356 } finally {
5357 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005358 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005359 }
5360
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005361 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005362 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005363 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005364 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005365 final long identity = Binder.clearCallingIdentity();
5366 try {
5367 Phone phone = getPhone(subId);
5368 if (phone != null) {
5369 return phone.isVideoEnabled();
5370 } else {
5371 return false;
5372 }
5373 } finally {
5374 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005375 }
5376 }
5377
5378 /**
5379 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5380 * defined in {@link ImsRegistrationImplBase}.
5381 */
5382 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005383 final long identity = Binder.clearCallingIdentity();
5384 try {
5385 Phone phone = getPhone(subId);
5386 if (phone != null) {
5387 return phone.getImsRegistrationTech();
5388 } else {
5389 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5390 }
5391 } finally {
5392 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005393 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005394 }
5395
Stuart Scott8eef64f2015-04-08 15:13:54 -07005396 @Override
5397 public void factoryReset(int subId) {
5398 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005399 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5400 return;
5401 }
5402
Svet Ganovcc087f82015-05-12 20:35:54 -07005403 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005404
Svet Ganovcc087f82015-05-12 20:35:54 -07005405 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005406 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5407 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005408 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005409 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005410 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005411 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5412 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005413 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005414 // There has been issues when Sms raw table somehow stores orphan
5415 // fragments. They lead to garbled message when new fragments come
5416 // in and combined with those stale ones. In case this happens again,
5417 // user can reset all network settings which will clean up this table.
5418 cleanUpSmsRawTable(getDefaultPhone().getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07005419 } finally {
5420 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005421 }
5422 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005423
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005424 private void cleanUpSmsRawTable(Context context) {
5425 ContentResolver resolver = context.getContentResolver();
5426 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5427 resolver.delete(uri, null, null);
5428 }
5429
Narayan Kamath1c496c22015-04-16 14:40:19 +01005430 @Override
chen xu5d3637b2019-01-21 23:31:38 -08005431 public String getSimLocaleForSubscriber(int subId) {
5432 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5433 final Phone phone = getPhone(subId);
5434 if (phone == null) {
5435 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08005436 return null;
chen xu5d3637b2019-01-21 23:31:38 -08005437 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005438 final long identity = Binder.clearCallingIdentity();
5439 try {
chen xu5d3637b2019-01-21 23:31:38 -08005440 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5441 phone.getContext().getOpPackageName());
chen xu6291c472019-02-04 12:55:53 -08005442 if (info == null) {
5443 log("getSimLocaleForSubscriber, inactive subId: " + subId);
5444 return null;
5445 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005446 // Try and fetch the locale from the carrier properties or from the SIM language
5447 // preferences (EF-PL and EF-LI)...
5448 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005449 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08005450 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5451 if (localeFromDefaultSim != null) {
5452 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5453 if (DBG) log("Using locale from subId: " + subId + " locale: "
5454 + localeFromDefaultSim);
5455 return localeFromDefaultSim.toLanguageTag();
5456 } else {
5457 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005458 }
5459 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005460
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005461 // The SIM language preferences only store a language (e.g. fr = French), not an
5462 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5463 // the SIM and carrier preferences does not include a country we add the country
5464 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005465 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005466 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08005467 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005468 return mccLocale.toLanguageTag();
5469 }
5470
5471 if (DBG) log("No locale found - returning null");
5472 return null;
5473 } finally {
5474 Binder.restoreCallingIdentity(identity);
5475 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005476 }
5477
5478 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005479 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005480 }
5481
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005482 /**
5483 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5484 */
5485 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005486 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005487 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005488
Chenjie Yu1ba97252018-01-11 18:16:20 -08005489 private final ModemActivityInfo mLastModemActivityInfo =
5490 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
5491
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005492 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005493 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5494 * representing the state of the modem.
5495 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005496 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5497 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005498 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005499 */
5500 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005501 public void requestModemActivityInfo(ResultReceiver result) {
5502 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005503 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005504
5505 final long identity = Binder.clearCallingIdentity();
5506 try {
5507 ModemActivityInfo ret = null;
5508 synchronized (mLastModemActivityInfo) {
5509 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5510 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07005511 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07005512 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005513 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
5514 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005515 mergedTxTimeMs[i] = info.getTxTimeMillis()[i]
5516 + mLastModemActivityInfo.getTxTimeMillis()[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005517 }
5518 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005519 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
5520 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005521 mLastModemActivityInfo.setIdleTimeMillis(
5522 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
5523 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
5524 mLastModemActivityInfo.setRxTimeMillis(
5525 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
5526 mLastModemActivityInfo.setEnergyUsed(
5527 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005528 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005529 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
5530 mLastModemActivityInfo.getSleepTimeMillis(),
5531 mLastModemActivityInfo.getIdleTimeMillis(),
5532 mLastModemActivityInfo.getTxTimeMillis(),
5533 mLastModemActivityInfo.getRxTimeMillis(),
5534 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005535 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005536 Bundle bundle = new Bundle();
5537 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
5538 result.send(0, bundle);
5539 } finally {
5540 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005541 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005542 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005543
Siddharth Rayb8114062018-06-17 15:02:38 -07005544 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
5545 // less than total activity duration.
5546 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
5547 if (info == null) {
5548 return false;
5549 }
5550 int activityDurationMs =
5551 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
5552 int totalTxTimeMs = 0;
5553 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
5554 totalTxTimeMs += info.getTxTimeMillis()[i];
5555 }
5556 return (info.isValid()
5557 && (info.getSleepTimeMillis() <= activityDurationMs)
5558 && (info.getIdleTimeMillis() <= activityDurationMs)
5559 && (info.getRxTimeMillis() <= activityDurationMs)
5560 && (totalTxTimeMs <= activityDurationMs));
5561 }
5562
Jack Yu85bd38a2015-11-09 11:34:32 -08005563 /**
5564 * {@hide}
5565 * Returns the service state information on specified subscription.
5566 */
5567 @Override
5568 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005569 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005570 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08005571 return null;
5572 }
5573
Hall Liuf19c44f2018-11-27 14:38:17 -08005574 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
5575 LocationAccessPolicy.checkLocationPermission(mApp,
5576 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5577 .setCallingPackage(callingPackage)
5578 .setCallingPid(Binder.getCallingPid())
5579 .setCallingUid(Binder.getCallingUid())
5580 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07005581 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005582 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5583 .build());
5584
5585 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
5586 LocationAccessPolicy.checkLocationPermission(mApp,
5587 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5588 .setCallingPackage(callingPackage)
5589 .setCallingPid(Binder.getCallingPid())
5590 .setCallingUid(Binder.getCallingUid())
5591 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07005592 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005593 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5594 .build());
5595 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
5596 boolean hasFinePermission =
5597 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5598 boolean hasCoarsePermission =
5599 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5600
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005601 final long identity = Binder.clearCallingIdentity();
5602 try {
5603 final Phone phone = getPhone(subId);
5604 if (phone == null) {
5605 return null;
5606 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005607
Hall Liuf19c44f2018-11-27 14:38:17 -08005608 ServiceState ss = phone.getServiceState();
5609
5610 // Scrub out the location info in ServiceState depending on what level of access
5611 // the caller has.
5612 if (hasFinePermission) return ss;
5613 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
5614 return ss.sanitizeLocationInfo(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005615 } finally {
5616 Binder.restoreCallingIdentity(identity);
5617 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005618 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005619
5620 /**
5621 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
5622 *
5623 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5624 * voicemail ringtone.
5625 * @return The URI for the ringtone to play when receiving a voicemail from a specific
5626 * PhoneAccount.
5627 */
5628 @Override
5629 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005630 final long identity = Binder.clearCallingIdentity();
5631 try {
5632 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5633 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005634 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005635 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005636
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005637 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
5638 } finally {
5639 Binder.restoreCallingIdentity(identity);
5640 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005641 }
5642
5643 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005644 * Sets the per-account voicemail ringtone.
5645 *
5646 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5647 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5648 *
5649 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5650 * voicemail ringtone.
5651 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5652 * PhoneAccount.
5653 */
5654 @Override
5655 public void setVoicemailRingtoneUri(String callingPackage,
5656 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005657 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005658 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5659 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005660 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005661 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5662 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5663 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005664 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005665
5666 final long identity = Binder.clearCallingIdentity();
5667 try {
5668 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5669 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005670 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005671 }
5672 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5673 } finally {
5674 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005675 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005676 }
5677
5678 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005679 * Returns whether vibration is set for voicemail notification in Phone settings.
5680 *
5681 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5682 * voicemail vibration setting.
5683 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5684 */
5685 @Override
5686 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005687 final long identity = Binder.clearCallingIdentity();
5688 try {
5689 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5690 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005691 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005692 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005693
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005694 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5695 } finally {
5696 Binder.restoreCallingIdentity(identity);
5697 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005698 }
5699
Youhan Wange64578a2016-05-02 15:32:42 -07005700 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005701 * Sets the per-account voicemail vibration.
5702 *
5703 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5704 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5705 *
5706 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5707 * voicemail vibration setting.
5708 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5709 * specific PhoneAccount.
5710 */
5711 @Override
5712 public void setVoicemailVibrationEnabled(String callingPackage,
5713 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005714 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005715 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5716 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005717 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005718 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5719 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5720 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005721 }
5722
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005723 final long identity = Binder.clearCallingIdentity();
5724 try {
5725 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5726 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005727 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005728 }
5729 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5730 } finally {
5731 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005732 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005733 }
5734
5735 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005736 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5737 *
5738 * @throws SecurityException if the caller does not have the required permission
5739 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005740 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005741 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07005742 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005743 }
5744
5745 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005746 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5747 * permission.
5748 *
5749 * @throws SecurityException if the caller does not have the required permission
5750 */
5751 private void enforceSendSmsPermission() {
5752 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5753 }
5754
5755 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005756 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005757 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005758 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005759 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005760 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005761 final long identity = Binder.clearCallingIdentity();
5762 try {
5763 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005764 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005765 if (componentName == null) {
5766 throw new SecurityException(
5767 "Caller not current active visual voicemail package[null]");
5768 }
5769 String vvmPackage = componentName.getPackageName();
5770 if (!callingPackage.equals(vvmPackage)) {
5771 throw new SecurityException("Caller not current active visual voicemail package["
5772 + vvmPackage + "]");
5773 }
5774 } finally {
5775 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005776 }
5777 }
5778
5779 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005780 * Return the application ID for the app type.
5781 *
5782 * @param subId the subscription ID that this request applies to.
5783 * @param appType the uicc app type.
5784 * @return Application ID for specificied app type, or null if no uicc.
5785 */
5786 @Override
5787 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005788 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005789 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005790
5791 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005792 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005793 if (phone == null) {
5794 return null;
5795 }
5796 String aid = null;
5797 try {
5798 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5799 .getApplicationByType(appType).getAid();
5800 } catch (Exception e) {
5801 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5802 }
5803 return aid;
5804 } finally {
5805 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005806 }
Youhan Wange64578a2016-05-02 15:32:42 -07005807 }
5808
Youhan Wang4001d252016-05-11 10:29:41 -07005809 /**
5810 * Return the Electronic Serial Number.
5811 *
5812 * @param subId the subscription ID that this request applies to.
5813 * @return ESN or null if error.
5814 */
5815 @Override
5816 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005817 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005818 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005819
5820 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005821 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005822 if (phone == null) {
5823 return null;
5824 }
5825 String esn = null;
5826 try {
5827 esn = phone.getEsn();
5828 } catch (Exception e) {
5829 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5830 }
5831 return esn;
5832 } finally {
5833 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005834 }
Youhan Wang4001d252016-05-11 10:29:41 -07005835 }
5836
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005837 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005838 * Return the Preferred Roaming List Version.
5839 *
5840 * @param subId the subscription ID that this request applies to.
5841 * @return PRLVersion or null if error.
5842 */
5843 @Override
5844 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005845 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005846 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005847
5848 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005849 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005850 if (phone == null) {
5851 return null;
5852 }
5853 String cdmaPrlVersion = null;
5854 try {
5855 cdmaPrlVersion = phone.getCdmaPrlVersion();
5856 } catch (Exception e) {
5857 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5858 }
5859 return cdmaPrlVersion;
5860 } finally {
5861 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005862 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005863 }
5864
5865 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005866 * Get snapshot of Telephony histograms
5867 * @return List of Telephony histograms
5868 * @hide
5869 */
5870 @Override
5871 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005872 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5873 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005874
5875 final long identity = Binder.clearCallingIdentity();
5876 try {
5877 return RIL.getTelephonyRILTimingHistograms();
5878 } finally {
5879 Binder.restoreCallingIdentity(identity);
5880 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005881 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005882
5883 /**
5884 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08005885 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
5886 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005887 * Require system privileges. In the future we may add this to carrier APIs.
5888 *
Michele Berionne482f8202018-11-27 18:57:59 -08005889 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005890 */
5891 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08005892 @TelephonyManager.SetCarrierRestrictionResult
5893 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005894 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005895 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005896
Michele Berionne482f8202018-11-27 18:57:59 -08005897 if (carrierRestrictionRules == null) {
5898 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08005899 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005900
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005901 final long identity = Binder.clearCallingIdentity();
5902 try {
Michele Berionne482f8202018-11-27 18:57:59 -08005903 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07005904 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005905 } finally {
5906 Binder.restoreCallingIdentity(identity);
5907 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005908 }
5909
5910 /**
5911 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08005912 * Get the allowed carrier list and the excluded carrier list, including the priority between
5913 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005914 * Require system privileges. In the future we may add this to carrier APIs.
5915 *
Michele Berionne482f8202018-11-27 18:57:59 -08005916 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07005917 */
5918 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08005919 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005920 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07005921 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005922
5923 final long identity = Binder.clearCallingIdentity();
5924 try {
Michele Berionne482f8202018-11-27 18:57:59 -08005925 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
5926 if (response instanceof CarrierRestrictionRules) {
5927 return (CarrierRestrictionRules) response;
5928 }
5929 // Response is an Exception of some kind,
5930 // which is signalled to the user as a NULL retval
5931 return null;
5932 } catch (Exception e) {
5933 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
5934 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005935 } finally {
5936 Binder.restoreCallingIdentity(identity);
5937 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005938 }
5939
fionaxu59545b42016-05-25 15:53:37 -07005940 /**
5941 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5942 * @param subId the subscription ID that this action applies to.
5943 * @param enabled control enable or disable metered apns.
5944 * {@hide}
5945 */
5946 @Override
5947 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5948 enforceModifyPermission();
5949 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005950
5951 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005952 if (phone == null) {
5953 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5954 return;
5955 }
5956 try {
5957 phone.carrierActionSetMeteredApnsEnabled(enabled);
5958 } catch (Exception e) {
5959 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005960 } finally {
5961 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005962 }
5963 }
5964
5965 /**
5966 * Action set from carrier signalling broadcast receivers to enable/disable radio
5967 * @param subId the subscription ID that this action applies to.
5968 * @param enabled control enable or disable radio.
5969 * {@hide}
5970 */
5971 @Override
5972 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5973 enforceModifyPermission();
5974 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005975
5976 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005977 if (phone == null) {
5978 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5979 return;
5980 }
5981 try {
5982 phone.carrierActionSetRadioEnabled(enabled);
5983 } catch (Exception e) {
5984 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005985 } finally {
5986 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005987 }
5988 }
5989
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005990 /**
fionaxu8da9cb12017-05-23 15:02:46 -07005991 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
5992 * network status based on which carrier apps could apply actions accordingly,
5993 * enable/disable default url handler for example.
5994 *
5995 * @param subId the subscription ID that this action applies to.
5996 * @param report control start/stop reporting the default network status.
5997 * {@hide}
5998 */
5999 @Override
6000 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6001 enforceModifyPermission();
6002 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006003
6004 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006005 if (phone == null) {
6006 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6007 return;
6008 }
6009 try {
6010 phone.carrierActionReportDefaultNetworkStatus(report);
6011 } catch (Exception e) {
6012 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006013 } finally {
6014 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006015 }
6016 }
6017
6018 /**
fionaxud9622282017-07-17 17:51:30 -07006019 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6020 * @param subId the subscription ID that this action applies to.
6021 * {@hide}
6022 */
6023 @Override
6024 public void carrierActionResetAll(int subId) {
6025 enforceModifyPermission();
6026 final Phone phone = getPhone(subId);
6027 if (phone == null) {
6028 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6029 return;
6030 }
6031 try {
6032 phone.carrierActionResetAll();
6033 } catch (Exception e) {
6034 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6035 }
6036 }
6037
6038 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006039 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6040 * bug report is being generated.
6041 */
6042 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006043 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006044 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6045 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006046 writer.println("Permission Denial: can't dump Phone from pid="
6047 + Binder.getCallingPid()
6048 + ", uid=" + Binder.getCallingUid()
6049 + "without permission "
6050 + android.Manifest.permission.DUMP);
6051 return;
6052 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006053 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006054 }
Jack Yueb89b242016-06-22 13:27:47 -07006055
Brad Ebingerdac2f002018-04-03 15:17:52 -07006056 @Override
6057 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6058 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6059 throws RemoteException {
6060 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
6061 }
6062
Jack Yueb89b242016-06-22 13:27:47 -07006063 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006064 * Get aggregated video call data usage since boot.
6065 *
6066 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6067 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006068 * {@hide}
6069 */
6070 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006071 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006072 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6073 null);
6074
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006075 final long identity = Binder.clearCallingIdentity();
6076 try {
6077 // NetworkStatsService keeps tracking the active network interface and identity. It
6078 // records the delta with the corresponding network identity.
6079 // We just return the total video call data usage snapshot since boot.
6080 Phone phone = getPhone(subId);
6081 if (phone != null) {
6082 return phone.getVtDataUsage(perUidStats);
6083 }
6084 return null;
6085 } finally {
6086 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006087 }
Jack Yueb89b242016-06-22 13:27:47 -07006088 }
Jack Yu75ab2952016-07-08 14:29:33 -07006089
6090 /**
6091 * Policy control of data connection. Usually used when data limit is passed.
6092 * @param enabled True if enabling the data, otherwise disabling.
6093 * @param subId Subscription index
6094 * {@hide}
6095 */
6096 @Override
6097 public void setPolicyDataEnabled(boolean enabled, int subId) {
6098 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006099
6100 final long identity = Binder.clearCallingIdentity();
6101 try {
6102 Phone phone = getPhone(subId);
6103 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006104 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006105 }
6106 } finally {
6107 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006108 }
6109 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006110
6111 /**
6112 * Get Client request stats
6113 * @return List of Client Request Stats
6114 * @hide
6115 */
6116 @Override
6117 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006118 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006119 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006120 return null;
6121 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006122 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006123
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006124 final long identity = Binder.clearCallingIdentity();
6125 try {
6126 if (phone != null) {
6127 return phone.getClientRequestStats();
6128 }
6129
6130 return null;
6131 } finally {
6132 Binder.restoreCallingIdentity(identity);
6133 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006134 }
6135
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006136 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006137 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006138 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006139 }
Jack Yueb4124c2017-02-16 15:32:43 -08006140
6141 /**
Grace Chen70990072017-03-24 17:21:30 -07006142 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006143 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006144 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006145 * @param state State of SIM (power down, power up, pass through)
6146 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6147 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6148 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006149 *
6150 **/
6151 @Override
Grace Chen70990072017-03-24 17:21:30 -07006152 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006153 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006154 Phone phone = PhoneFactory.getPhone(slotIndex);
6155
vagdeviaf9a5b92018-08-15 16:01:53 -07006156 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6157
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006158 final long identity = Binder.clearCallingIdentity();
6159 try {
6160 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006161 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006162 }
6163 } finally {
6164 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006165 }
6166 }
Shuo Qiandd210312017-04-12 22:11:33 +00006167
Tyler Gunn65d45c22017-06-05 11:22:26 -07006168 private boolean isUssdApiAllowed(int subId) {
6169 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006170 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006171 if (configManager == null) {
6172 return false;
6173 }
6174 PersistableBundle pb = configManager.getConfigForSubId(subId);
6175 if (pb == null) {
6176 return false;
6177 }
6178 return pb.getBoolean(
6179 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6180 }
6181
Shuo Qiandd210312017-04-12 22:11:33 +00006182 /**
6183 * Check if phone is in emergency callback mode
6184 * @return true if phone is in emergency callback mode
6185 * @param subId sub id
6186 */
goneil9c5f4872017-12-05 14:07:56 -08006187 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006188 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006189 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006190 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006191
6192 final long identity = Binder.clearCallingIdentity();
6193 try {
6194 if (phone != null) {
6195 return phone.isInEcm();
6196 } else {
6197 return false;
6198 }
6199 } finally {
6200 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006201 }
6202 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006203
6204 /**
6205 * Get the current signal strength information for the given subscription.
6206 * Because this information is not updated when the device is in a low power state
6207 * it should not be relied-upon to be current.
6208 * @param subId Subscription index
6209 * @return the most recent cached signal strength info from the modem
6210 */
6211 @Override
6212 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006213 final long identity = Binder.clearCallingIdentity();
6214 try {
6215 Phone p = getPhone(subId);
6216 if (p == null) {
6217 return null;
6218 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006219
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006220 return p.getSignalStrength();
6221 } finally {
6222 Binder.restoreCallingIdentity(identity);
6223 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006224 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006225
Pengquan Meng77b7f132018-08-22 14:49:57 -07006226 /**
Chen Xuf792fd62018-10-17 17:54:36 +00006227 * Get the current modem radio state for the given slot.
6228 * @param slotIndex slot index.
6229 * @param callingPackage the name of the package making the call.
6230 * @return the current radio power state from the modem
6231 */
6232 @Override
6233 public int getRadioPowerState(int slotIndex, String callingPackage) {
6234 Phone phone = PhoneFactory.getPhone(slotIndex);
6235 if (phone != null) {
6236 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6237 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
6238 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6239 }
6240
6241 final long identity = Binder.clearCallingIdentity();
6242 try {
6243 return phone.getRadioPowerState();
6244 } finally {
6245 Binder.restoreCallingIdentity(identity);
6246 }
6247 }
6248 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6249 }
6250
6251 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07006252 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6253 *
6254 * <p>Requires one of the following permissions:
6255 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6256 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6257 * privileges.
6258 *
6259 * @param subId subscription id
6260 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6261 * {@code false}.
6262 */
6263 @Override
6264 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006265 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6266 null /* message */);
6267
Pengquan Menga1bb6272018-09-06 09:59:22 -07006268 boolean isEnabled = false;
6269 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07006270 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006271 Phone phone = getPhone(subId);
6272 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006273 } catch (Exception e) {
6274 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6275 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07006276 } finally {
6277 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006278 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006279 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006280 }
6281
6282
6283 /**
6284 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6285 *
6286 * <p> Requires permission:
6287 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6288 * privileges.
6289 *
6290 * @param subId subscription id
6291 * @param isEnabled {@code true} means enable, {@code false} means disable.
6292 */
6293 @Override
6294 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006295 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6296 mApp, subId, "setDataRoamingEnabled");
6297
Pengquan Menga1bb6272018-09-06 09:59:22 -07006298 final long identity = Binder.clearCallingIdentity();
6299 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006300 Phone phone = getPhone(subId);
6301 if (phone != null) {
6302 phone.setDataRoamingEnabled(isEnabled);
6303 }
6304 } finally {
6305 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006306 }
6307 }
6308
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006309 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006310 public boolean isManualNetworkSelectionAllowed(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006311 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6312 mApp, subId, "isManualNetworkSelectionAllowed");
6313
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006314 boolean isAllowed = true;
6315 final long identity = Binder.clearCallingIdentity();
6316 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006317 Phone phone = getPhone(subId);
6318 if (phone != null) {
6319 isAllowed = phone.isCspPlmnEnabled();
6320 }
6321 } finally {
6322 Binder.restoreCallingIdentity(identity);
6323 }
6324 return isAllowed;
6325 }
6326
6327 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006328 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006329 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08006330 try {
6331 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07006332 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08006333 } catch (SecurityException e) {
6334 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6335 // has carrier privileges on an active UICC
6336 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6337 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006338 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08006339 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006340 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006341
6342 final long identity = Binder.clearCallingIdentity();
6343 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006344 UiccController uiccController = UiccController.getInstance();
6345 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07006346 if (hasReadPermission) {
6347 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006348 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07006349
6350 // Remove private info if the caller doesn't have access
6351 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6352 for (UiccCardInfo cardInfo : cardInfos) {
6353 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6354 // is available
6355 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
6356 if (card == null || card.getUiccProfile() == null) {
6357 // assume no access if the card or profile is unavailable
6358 filteredInfos.add(cardInfo.getUnprivileged());
6359 continue;
6360 }
6361 UiccProfile profile = card.getUiccProfile();
6362 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6363 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6364 filteredInfos.add(cardInfo);
6365 } else {
6366 filteredInfos.add(cardInfo.getUnprivileged());
6367 }
6368 }
6369 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08006370 } finally {
6371 Binder.restoreCallingIdentity(identity);
6372 }
6373 }
6374
6375 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006376 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006377 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006378
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006379 final long identity = Binder.clearCallingIdentity();
6380 try {
6381 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6382 if (slots == null) {
6383 Rlog.i(LOG_TAG, "slots is null.");
6384 return null;
6385 }
6386
6387 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6388 for (int i = 0; i < slots.length; i++) {
6389 UiccSlot slot = slots[i];
6390 if (slot == null) {
6391 continue;
6392 }
6393
Jordan Liu7be7e652019-05-06 18:55:02 +00006394 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006395 UiccCard card = slot.getUiccCard();
6396 if (card != null) {
6397 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00006398 } else {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006399 cardId = slot.getIccId();
6400 }
6401
6402 int cardState = 0;
6403 switch (slot.getCardState()) {
6404 case CARDSTATE_ABSENT:
6405 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6406 break;
6407 case CARDSTATE_PRESENT:
6408 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6409 break;
6410 case CARDSTATE_ERROR:
6411 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6412 break;
6413 case CARDSTATE_RESTRICTED:
6414 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6415 break;
6416 default:
6417 break;
6418
6419 }
6420
6421 infos[i] = new UiccSlotInfo(
6422 slot.isActive(),
6423 slot.isEuicc(),
6424 cardId,
6425 cardState,
6426 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08006427 slot.isExtendedApduSupported(),
6428 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006429 }
6430 return infos;
6431 } finally {
6432 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006433 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006434 }
6435
6436 @Override
6437 public boolean switchSlots(int[] physicalSlots) {
6438 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006439
6440 final long identity = Binder.clearCallingIdentity();
6441 try {
6442 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6443 } finally {
6444 Binder.restoreCallingIdentity(identity);
6445 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006446 }
Jack Yu4c988042018-02-27 15:30:01 -08006447
6448 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006449 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006450 final long identity = Binder.clearCallingIdentity();
6451 try {
6452 return UiccController.getInstance().getCardIdForDefaultEuicc();
6453 } finally {
6454 Binder.restoreCallingIdentity(identity);
6455 }
6456 }
6457
6458 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006459 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6460 enforceModifyPermission();
6461 final Phone phone = getPhone(subId);
6462 if (phone == null) {
6463 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6464 return;
6465 }
6466
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006467 final long identity = Binder.clearCallingIdentity();
6468 try {
6469 phone.setRadioIndicationUpdateMode(filters, mode);
6470 } finally {
6471 Binder.restoreCallingIdentity(identity);
6472 }
Jack Yu4c988042018-02-27 15:30:01 -08006473 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006474
6475 /**
goneil47ffb6e2018-04-06 15:40:58 -07006476 * A test API to reload the UICC profile.
6477 *
6478 * <p>Requires that the calling app has permission
6479 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6480 * @hide
6481 */
6482 @Override
6483 public void refreshUiccProfile(int subId) {
6484 enforceModifyPermission();
6485
6486 final long identity = Binder.clearCallingIdentity();
6487 try {
6488 Phone phone = getPhone(subId);
6489 if (phone == null) {
6490 return;
6491 }
6492 UiccCard uiccCard = phone.getUiccCard();
6493 if (uiccCard == null) {
6494 return;
6495 }
6496 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6497 if (uiccProfile == null) {
6498 return;
6499 }
6500 uiccProfile.refresh();
6501 } finally {
6502 Binder.restoreCallingIdentity(identity);
6503 }
6504 }
6505
6506 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006507 * Returns false if the mobile data is disabled by default, otherwise return true.
6508 */
6509 private boolean getDefaultDataEnabled() {
6510 return "true".equalsIgnoreCase(
6511 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
6512 }
6513
6514 /**
6515 * Returns true if the data roaming is enabled by default, i.e the system property
6516 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
6517 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
6518 */
6519 private boolean getDefaultDataRoamingEnabled(int subId) {
6520 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006521 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006522 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
6523 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
6524 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
6525 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
6526 return isDataRoamingEnabled;
6527 }
6528
6529 /**
6530 * Returns the default network type for the given {@code subId}, if the default network type is
6531 * not set, return {@link Phone#PREFERRED_NT_MODE}.
6532 */
6533 private int getDefaultNetworkType(int subId) {
6534 return Integer.parseInt(
6535 TelephonyManager.getTelephonyProperty(
6536 mSubscriptionController.getPhoneId(subId),
6537 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
6538 String.valueOf(Phone.PREFERRED_NT_MODE)));
6539 }
fionaxua13278b2018-03-21 00:08:13 -07006540
6541 @Override
6542 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07006543 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07006544 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006545
6546 final long identity = Binder.clearCallingIdentity();
6547 try {
6548 final Phone phone = getPhone(subId);
6549 if (phone == null) {
6550 loge("setCarrierTestOverride fails with invalid subId: " + subId);
6551 return;
6552 }
chen xueaba88a2019-03-15 13:15:10 -07006553 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
6554 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006555 } finally {
6556 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006557 }
fionaxua13278b2018-03-21 00:08:13 -07006558 }
6559
6560 @Override
6561 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006562 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006563
6564 final long identity = Binder.clearCallingIdentity();
6565 try {
6566 final Phone phone = getPhone(subId);
6567 if (phone == null) {
6568 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
6569 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
6570 }
6571 return phone.getCarrierIdListVersion();
6572 } finally {
6573 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006574 }
fionaxua13278b2018-03-21 00:08:13 -07006575 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07006576
6577 @Override
6578 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
6579 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6580 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
6581 return -1;
6582 }
6583
6584 final long identity = Binder.clearCallingIdentity();
6585 try {
6586 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
6587 } finally {
6588 Binder.restoreCallingIdentity(identity);
6589 }
6590 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006591
6592 @Override
6593 public int getCdmaRoamingMode(int subId) {
6594 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6595 mApp, subId, "getCdmaRoamingMode");
6596
6597 final long identity = Binder.clearCallingIdentity();
6598 try {
6599 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
6600 } finally {
6601 Binder.restoreCallingIdentity(identity);
6602 }
6603 }
6604
6605 @Override
6606 public boolean setCdmaRoamingMode(int subId, int mode) {
6607 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6608 mApp, subId, "setCdmaRoamingMode");
6609
6610 final long identity = Binder.clearCallingIdentity();
6611 try {
6612 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
6613 } finally {
6614 Binder.restoreCallingIdentity(identity);
6615 }
6616 }
6617
6618 @Override
6619 public boolean setCdmaSubscriptionMode(int subId, int mode) {
6620 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6621 mApp, subId, "setCdmaSubscriptionMode");
6622
6623 final long identity = Binder.clearCallingIdentity();
6624 try {
6625 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
6626 } finally {
6627 Binder.restoreCallingIdentity(identity);
6628 }
6629 }
Makoto Onukida3bf792018-09-18 16:06:29 -07006630
6631 private void ensureUserRunning(int userId) {
6632 if (!mUserManager.isUserRunning(userId)) {
6633 throw new IllegalStateException("User " + userId + " does not exist or not running");
6634 }
6635 }
6636
6637 /**
6638 * Returns a list of SMS apps on a given user.
6639 *
6640 * Only the shell user (UID 2000 or 0) can call it.
6641 * Target user must be running.
6642 */
6643 @Override
6644 public String[] getSmsApps(int userId) {
6645 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
6646 ensureUserRunning(userId);
6647
6648 final Collection<SmsApplicationData> apps =
6649 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
6650
6651 String[] ret = new String[apps.size()];
6652 int i = 0;
6653 for (SmsApplicationData app : apps) {
6654 ret[i++] = app.mPackageName;
6655 }
6656 return ret;
6657 }
6658
6659 /**
6660 * Returns the default SMS app package name on a given user.
6661 *
6662 * Only the shell user (UID 2000 or 0) can call it.
6663 * Target user must be running.
6664 */
6665 @Override
6666 public String getDefaultSmsApp(int userId) {
6667 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
6668 ensureUserRunning(userId);
6669
6670 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
6671 /* updateIfNeeded= */ true, userId);
6672 return cn == null ? null : cn.getPackageName();
6673 }
6674
6675 /**
6676 * Set a package as the default SMS app on a given user.
6677 *
6678 * Only the shell user (UID 2000 or 0) can call it.
6679 * Target user must be running.
6680 */
6681 @Override
6682 public void setDefaultSmsApp(int userId, String packageName) {
6683 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
6684 ensureUserRunning(userId);
6685
6686 boolean found = false;
6687 for (String pkg : getSmsApps(userId)) {
6688 if (TextUtils.equals(packageName, pkg)) {
6689 found = true;
6690 break;
6691 }
6692 }
6693 if (!found) {
6694 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
6695 }
6696
6697 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
6698 }
sqianc5eccab2018-10-19 18:46:41 -07006699
6700 @Override
sqian8c685422019-02-22 15:55:18 -08006701 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
sqianc5eccab2018-10-19 18:46:41 -07006702 String callingPackage) {
sqian11b7a0e2018-12-05 18:48:28 -08006703 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
sqian8c685422019-02-22 15:55:18 -08006704 mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08006705 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6706 }
6707 final long identity = Binder.clearCallingIdentity();
6708 try {
sqian854d44b2018-12-12 16:48:18 -08006709 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
6710 for (Phone phone: PhoneFactory.getPhones()) {
6711 if (phone.getEmergencyNumberTracker() != null
6712 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
6713 emergencyNumberListInternal.put(
6714 phone.getSubId(),
6715 phone.getEmergencyNumberTracker().getEmergencyNumberList());
6716 }
sqian11b7a0e2018-12-05 18:48:28 -08006717 }
sqian854d44b2018-12-12 16:48:18 -08006718 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08006719 } finally {
6720 Binder.restoreCallingIdentity(identity);
6721 }
sqianc5eccab2018-10-19 18:46:41 -07006722 }
6723
6724 @Override
sqian8c685422019-02-22 15:55:18 -08006725 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006726 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08006727 if (!exactMatch) {
6728 TelephonyPermissions
6729 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08006730 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08006731 }
6732 final long identity = Binder.clearCallingIdentity();
6733 try {
sqian854d44b2018-12-12 16:48:18 -08006734 for (Phone phone: PhoneFactory.getPhones()) {
6735 if (phone.getEmergencyNumberTracker() != null
6736 && phone.getEmergencyNumberTracker() != null) {
6737 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
6738 number, exactMatch)) {
6739 return true;
sqian11b7a0e2018-12-05 18:48:28 -08006740 }
6741 }
sqian11b7a0e2018-12-05 18:48:28 -08006742 }
6743 return false;
6744 } finally {
6745 Binder.restoreCallingIdentity(identity);
6746 }
6747 }
6748
sqianf4ca7ed2019-01-15 18:32:07 -08006749 /**
6750 * Update emergency number list for test mode.
6751 */
6752 @Override
6753 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
6754 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6755 "updateEmergencyNumberListTestMode");
6756
6757 final long identity = Binder.clearCallingIdentity();
6758 try {
6759 for (Phone phone: PhoneFactory.getPhones()) {
6760 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6761 if (tracker != null) {
6762 tracker.executeEmergencyNumberTestModeCommand(action, num);
6763 }
6764 }
6765 } finally {
6766 Binder.restoreCallingIdentity(identity);
6767 }
6768 }
6769
6770 /**
6771 * Get the full emergency number list for test mode.
6772 */
6773 @Override
6774 public List<String> getEmergencyNumberListTestMode() {
6775 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6776 "getEmergencyNumberListTestMode");
6777
6778 final long identity = Binder.clearCallingIdentity();
6779 try {
6780 Set<String> emergencyNumbers = new HashSet<>();
6781 for (Phone phone: PhoneFactory.getPhones()) {
6782 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6783 if (tracker != null) {
6784 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
6785 emergencyNumbers.add(num.getNumber());
6786 }
6787 }
6788 }
6789 return new ArrayList<>(emergencyNumbers);
6790 } finally {
6791 Binder.restoreCallingIdentity(identity);
6792 }
6793 }
6794
chen xud6b45bd2018-10-30 22:27:10 -07006795 @Override
6796 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
6797 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
6798 Phone phone = getPhone(subId);
6799 if (phone == null) {
6800 return null;
6801 }
6802 final long identity = Binder.clearCallingIdentity();
6803 try {
6804 UiccProfile profile = UiccController.getInstance()
6805 .getUiccProfileForPhone(phone.getPhoneId());
6806 if (profile != null) {
6807 return profile.getCertsFromCarrierPrivilegeAccessRules();
6808 }
6809 } finally {
6810 Binder.restoreCallingIdentity(identity);
6811 }
6812 return null;
6813 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08006814
6815 /**
6816 * Enable or disable a modem stack.
6817 */
6818 @Override
6819 public boolean enableModemForSlot(int slotIndex, boolean enable) {
6820 enforceModifyPermission();
6821
6822 final long identity = Binder.clearCallingIdentity();
6823 try {
6824 Phone phone = PhoneFactory.getPhone(slotIndex);
6825 if (phone == null) {
6826 return false;
6827 } else {
6828 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
6829 }
6830 } finally {
6831 Binder.restoreCallingIdentity(identity);
6832 }
6833 }
Michelecea4cf22018-12-21 15:00:11 -08006834
Malcolm Chen4bcd9822019-03-27 18:34:05 -07006835 /**
6836 * Whether a modem stack is enabled or not.
6837 */
6838 @Override
6839 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage) {
6840 Phone phone = PhoneFactory.getPhone(slotIndex);
6841 if (phone == null) return false;
6842
6843 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6844 mApp, phone.getSubId(), callingPackage, "isModemEnabledForSlot")) {
6845 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6846 }
6847
6848 final long identity = Binder.clearCallingIdentity();
6849 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07006850 try {
6851 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
6852 } catch (NoSuchElementException ex) {
6853 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
6854 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07006855 } finally {
6856 Binder.restoreCallingIdentity(identity);
6857 }
6858 }
6859
Michelecea4cf22018-12-21 15:00:11 -08006860 @Override
Michele0ea7d782019-03-19 14:58:42 -07006861 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08006862 enforceModifyPermission();
6863
6864 final long identity = Binder.clearCallingIdentity();
6865 try {
6866 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07006867 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08006868 .commit();
6869 } finally {
6870 Binder.restoreCallingIdentity(identity);
6871 }
6872 }
6873
6874 @Override
Michele0ea7d782019-03-19 14:58:42 -07006875 @TelephonyManager.IsMultiSimSupportedResult
6876 public int isMultiSimSupported(String callingPackage) {
Michele4245e952019-02-04 11:36:23 -08006877 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Michele0ea7d782019-03-19 14:58:42 -07006878 getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) {
6879 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08006880 }
Michelecea4cf22018-12-21 15:00:11 -08006881
6882 final long identity = Binder.clearCallingIdentity();
6883 try {
Michele0ea7d782019-03-19 14:58:42 -07006884 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08006885 } finally {
6886 Binder.restoreCallingIdentity(identity);
6887 }
6888 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006889
Michele0ea7d782019-03-19 14:58:42 -07006890 @TelephonyManager.IsMultiSimSupportedResult
6891 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08006892 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
6893 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
6894 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07006895 loge("isMultiSimSupportedInternal: requires at least 2 cards");
6896 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006897 }
6898 // Check if the hardware supports multisim functionality. If usage of multisim is not
6899 // supported by the modem, indicate that it is restricted.
6900 PhoneCapability staticCapability =
6901 mPhoneConfigurationManager.getStaticPhoneCapability();
6902 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07006903 loge("isMultiSimSupportedInternal: no static configuration available");
6904 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006905 }
6906 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07006907 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
6908 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006909 }
6910 // Check if support of multiple SIMs is restricted by carrier
6911 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07006912 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08006913 }
6914
Michele0ea7d782019-03-19 14:58:42 -07006915 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08006916 }
6917
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006918 /**
6919 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08006920 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
6921 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
6922 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006923 * @param numOfSims number of active sims we want to switch to
6924 */
6925 @Override
6926 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08006927 if (numOfSims == 1) {
6928 enforceModifyPermission();
6929 } else {
6930 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6931 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
6932 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006933 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08006934
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006935 try {
Michele30b57b22019-03-01 12:01:14 -08006936 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07006937 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08006938 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
6939 return;
6940 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006941 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
6942 } finally {
6943 Binder.restoreCallingIdentity(identity);
6944 }
6945 }
6946
6947 /**
chen xub4baa772019-04-03 10:23:41 -07006948 * Get whether making changes to modem configurations will trigger reboot.
6949 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08006950 */
6951 @Override
chen xub4baa772019-04-03 10:23:41 -07006952 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage) {
6953 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6954 mApp, subId, callingPackage, "doesSwitchMultiSimConfigTriggerReboot")) {
6955 return false;
6956 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08006957 final long identity = Binder.clearCallingIdentity();
6958 try {
6959 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
6960 } finally {
6961 Binder.restoreCallingIdentity(identity);
6962 }
6963 }
6964
Nathan Harold29f5f052019-02-15 13:41:57 -08006965 private void updateModemStateMetrics() {
6966 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
6967 // TODO: check the state for each modem if the api is ready.
6968 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
6969 }
6970
Pengquan Meng3889a572019-01-23 11:16:29 -08006971 @Override
6972 public int[] getSlotsMapping() {
6973 enforceReadPrivilegedPermission("getSlotsMapping");
6974
6975 final long identity = Binder.clearCallingIdentity();
6976 try {
6977 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
6978 // All logical slots should have a mapping to a physical slot.
6979 int[] logicalSlotsMapping = new int[phoneCount];
6980 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
6981 for (int i = 0; i < slotInfos.length; i++) {
6982 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
6983 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
6984 }
6985 }
6986 return logicalSlotsMapping;
6987 } finally {
6988 Binder.restoreCallingIdentity(identity);
6989 }
6990 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08006991
6992 /**
6993 * Get the IRadio HAL Version
6994 */
6995 @Override
6996 public int getRadioHalVersion() {
6997 Phone phone = getDefaultPhone();
6998 if (phone == null) return -1;
6999 HalVersion hv = phone.getHalVersion();
7000 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7001 return hv.major * 100 + hv.minor;
7002 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007003
7004 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007005 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7006 * corresponding network requests on a subId.
7007 *
7008 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007009 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007010 * 2) APN is un-metered for this subscription, or
7011 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
7012 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on.
7013 *
7014 * @return whether data is allowed for a apn type.
7015 *
7016 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007017 */
7018 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007019 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007020 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Malcolm Chene5ad5792019-04-18 13:51:02 -07007021 mApp, subId, callingPackage, "isDataEnabledForApn")) {
7022 throw new SecurityException("Needs READ_PHONE_STATE for isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007023 }
7024
7025 // Now that all security checks passes, perform the operation as ourselves.
7026 final long identity = Binder.clearCallingIdentity();
7027 try {
7028 Phone phone = getPhone(subId);
7029 if (phone == null) return false;
7030
Jack Yu41407ee2019-05-13 16:54:09 -07007031 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07007032 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7033 } finally {
7034 Binder.restoreCallingIdentity(identity);
7035 }
7036 }
7037
7038 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07007039 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07007040 enforceReadPrivilegedPermission("isApnMetered");
7041
7042 // Now that all security checks passes, perform the operation as ourselves.
7043 final long identity = Binder.clearCallingIdentity();
7044 try {
7045 Phone phone = getPhone(subId);
7046 if (phone == null) return true; // By default return true.
7047
Jack Yu41407ee2019-05-13 16:54:09 -07007048 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007049 } finally {
7050 Binder.restoreCallingIdentity(identity);
7051 }
7052 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007053
7054 @Override
7055 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
7056 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
7057 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
7058 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
7059 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
7060 }
7061 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
7062 Intent intent = new Intent();
7063 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
7064 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7065 // Bring up choose default SMS subscription dialog right now
7066 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
7067 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
7068 mApp.startActivity(intent);
7069 }
chen xud5ca2d52019-05-28 15:20:57 -07007070
7071 @Override
7072 public String getMmsUAProfUrl(int subId) {
7073 //TODO investigate if this API should require proper permission check in R b/133791609
7074 final long identity = Binder.clearCallingIdentity();
7075 try {
7076 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7077 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
7078 } finally {
7079 Binder.restoreCallingIdentity(identity);
7080 }
7081 }
7082
7083 @Override
7084 public String getMmsUserAgent(int subId) {
7085 //TODO investigate if this API should require proper permission check in R b/133791609
7086 final long identity = Binder.clearCallingIdentity();
7087 try {
7088 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7089 .getString(com.android.internal.R.string.config_mms_user_agent);
7090 } finally {
7091 Binder.restoreCallingIdentity(identity);
7092 }
7093 }
Jack Yub07d4972019-05-28 16:12:25 -07007094
7095 @Override
7096 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
7097 enforceModifyPermission();
7098
7099 // Now that all security checks passes, perform the operation as ourselves.
7100 final long identity = Binder.clearCallingIdentity();
7101 try {
7102 Phone phone = getPhone(subId);
7103 if (phone == null) return false;
7104
7105 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
7106 } finally {
7107 Binder.restoreCallingIdentity(identity);
7108 }
7109 }
7110
7111 @Override
7112 public boolean isDataAllowedInVoiceCall(int subId) {
7113 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
7114
7115 // Now that all security checks passes, perform the operation as ourselves.
7116 final long identity = Binder.clearCallingIdentity();
7117 try {
7118 Phone phone = getPhone(subId);
7119 if (phone == null) return false;
7120
7121 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
7122 } finally {
7123 Binder.restoreCallingIdentity(identity);
7124 }
7125 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007126}