blob: 500a77982675d0d2528b36caad87564cc5f89d4f [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;
Jack Yu84291ec2017-05-26 16:07:50 -070082import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080083import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080084import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070085import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070086import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080087import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080088import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000089import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070090import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070091import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070092import android.telephony.cdma.CdmaCellLocation;
Jack Yub5d8f642018-11-26 11:20:48 -080093import android.telephony.data.ApnSetting;
94import 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;
Hall Liud892bec2018-11-30 14:51:45 -0800124import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700125import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800126import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700127import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100128import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700129import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700130import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700131import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700132import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800133import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700134import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700135import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700136import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700137import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700138import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700139import com.android.internal.telephony.ServiceStateTracker;
Makoto Onukida3bf792018-09-18 16:06:29 -0700140import com.android.internal.telephony.SmsApplication;
141import com.android.internal.telephony.SmsApplication.SmsApplicationData;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800142import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800143import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700144import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800145import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700146import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800147import com.android.internal.telephony.ims.ImsResolver;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800148import com.android.internal.telephony.metrics.TelephonyMetrics;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700149import com.android.internal.telephony.uicc.IccIoResult;
150import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800151import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700152import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800153import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700154import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800155import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000156import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700157import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800158import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700159import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800160import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700161import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700162import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800163
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700164import java.io.FileDescriptor;
165import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800166import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700167import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800168import java.util.Arrays;
Makoto Onukida3bf792018-09-18 16:06:29 -0700169import java.util.Collection;
sqian11b7a0e2018-12-05 18:48:28 -0800170import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800171import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800172import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100173import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800174import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700175import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800176import java.util.Set;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700177
178/**
179 * Implementation of the ITelephony interface.
180 */
Santos Cordon117fee72014-05-16 17:56:12 -0700181public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700182 private static final String LOG_TAG = "PhoneInterfaceManager";
183 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
184 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800185 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700186
187 // Message codes used with mMainThreadHandler
188 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700189 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
190 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700191 private static final int CMD_OPEN_CHANNEL = 9;
192 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
193 private static final int CMD_CLOSE_CHANNEL = 11;
194 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800195 private static final int CMD_NV_READ_ITEM = 13;
196 private static final int EVENT_NV_READ_ITEM_DONE = 14;
197 private static final int CMD_NV_WRITE_ITEM = 15;
198 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
199 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
200 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700201 private static final int CMD_RESET_MODEM_CONFIG = 19;
202 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800203 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
204 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
205 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
206 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800207 private static final int CMD_SEND_ENVELOPE = 25;
208 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000209 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
210 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700211 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
212 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
213 private static final int CMD_EXCHANGE_SIM_IO = 31;
214 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800215 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
216 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700217 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
218 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700219 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
220 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700221 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
222 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
223 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
224 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700225 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
226 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
227 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
228 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700229 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800230 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
231 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000232 private static final int CMD_SWITCH_SLOTS = 50;
233 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700234 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
235 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
236 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
237 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
238 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
239 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
240 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
241 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700242 private static final int CMD_GET_ALL_CELL_INFO = 60;
243 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
244 private static final int CMD_GET_CELL_LOCATION = 62;
245 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700246 private static final int CMD_MODEM_REBOOT = 64;
247 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700248 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
249 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800250 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
251 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700252 private static final int CMD_GET_MODEM_STATUS = 70;
253 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700254
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800255 // Parameters of select command.
256 private static final int SELECT_COMMAND = 0xA4;
257 private static final int SELECT_P1 = 0x04;
258 private static final int SELECT_P2 = 0;
259 private static final int SELECT_P3 = 0x10;
260
Pengquan Meng85728fb2018-03-12 16:31:21 -0700261 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
262 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
263 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
264
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700265 /** The singleton instance. */
266 private static PhoneInterfaceManager sInstance;
267
Wink Saville3ab207e2014-11-20 13:07:20 -0800268 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800269 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700270 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800271 private AppOpsManager mAppOps;
272 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800273 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800274 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700275 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700276
Derek Tan97ebb422014-09-05 16:55:38 -0700277 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
278 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800279 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800280 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700281
Michelecea4cf22018-12-21 15:00:11 -0800282 // String to store multi SIM allowed
283 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
284
Derek Tan740e1672017-06-27 14:56:27 -0700285 // The AID of ISD-R.
286 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
287
yinxub1bed742017-04-17 11:45:04 -0700288 private NetworkScanRequestTracker mNetworkScanRequestTracker;
289
David Kelly5e06a7f2018-03-12 14:10:59 +0000290 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
291 private static final int MANUFACTURER_CODE_LENGTH = 8;
292
Derek Tan89e89d42014-07-08 17:00:10 -0700293 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700294 * A request object to use for transmitting data to an ICC.
295 */
296 private static final class IccAPDUArgument {
297 public int channel, cla, command, p1, p2, p3;
298 public String data;
299
300 public IccAPDUArgument(int channel, int cla, int command,
301 int p1, int p2, int p3, String data) {
302 this.channel = channel;
303 this.cla = cla;
304 this.command = command;
305 this.p1 = p1;
306 this.p2 = p2;
307 this.p3 = p3;
308 this.data = data;
309 }
310 }
311
312 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700313 * A request object to use for transmitting data to an ICC.
314 */
315 private static final class ManualNetworkSelectionArgument {
316 public OperatorInfo operatorInfo;
317 public boolean persistSelection;
318
319 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
320 this.operatorInfo = operatorInfo;
321 this.persistSelection = persistSelection;
322 }
323 }
324
325 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700326 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
327 * request after sending. The main thread will notify the request when it is complete.
328 */
329 private static final class MainThreadRequest {
330 /** The argument to use for the request */
331 public Object argument;
332 /** The result of the request that is run on the main thread */
333 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800334 // The subscriber id that this request applies to. Defaults to
335 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
336 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700337
Nathan Harold92bed182018-10-12 18:16:49 -0700338 // In cases where subId is unavailable, the caller needs to specify the phone.
339 public Phone phone;
340
vagdeviaf9a5b92018-08-15 16:01:53 -0700341 public WorkSource workSource;
342
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700343 public MainThreadRequest(Object argument) {
344 this.argument = argument;
345 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800346
Nathan Harold92bed182018-10-12 18:16:49 -0700347 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
348 this.argument = argument;
349 if (phone != null) {
350 this.phone = phone;
351 }
352 this.workSource = workSource;
353 }
354
vagdeviaf9a5b92018-08-15 16:01:53 -0700355 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800356 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800357 if (subId != null) {
358 this.subId = subId;
359 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700360 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800361 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700362 }
363
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800364 private static final class IncomingThirdPartyCallArgs {
365 public final ComponentName component;
366 public final String callId;
367 public final String callerDisplayName;
368
369 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
370 String callerDisplayName) {
371 this.component = component;
372 this.callId = callId;
373 this.callerDisplayName = callerDisplayName;
374 }
375 }
376
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700377 /**
378 * A handler that processes messages on the main thread in the phone process. Since many
379 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
380 * inbound binder threads to the main thread in the phone process. The Binder thread
381 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
382 * on, which will be notified when the operation completes and will contain the result of the
383 * request.
384 *
385 * <p>If a MainThreadRequest object is provided in the msg.obj field,
386 * note that request.result must be set to something non-null for the calling thread to
387 * unblock.
388 */
389 private final class MainThreadHandler extends Handler {
390 @Override
391 public void handleMessage(Message msg) {
392 MainThreadRequest request;
393 Message onCompleted;
394 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800395 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700396 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800397 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700398
399 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700400 case CMD_HANDLE_USSD_REQUEST: {
401 request = (MainThreadRequest) msg.obj;
402 final Phone phone = getPhoneFromRequest(request);
403 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
404 String ussdRequest = ussdObject.first;
405 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700406
Pengquan Menga1bb6272018-09-06 09:59:22 -0700407 if (!isUssdApiAllowed(request.subId)) {
408 // Carrier does not support use of this API, return failure.
409 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
410 UssdResponse response = new UssdResponse(ussdRequest, null);
411 Bundle returnData = new Bundle();
412 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
413 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700414
Pengquan Menga1bb6272018-09-06 09:59:22 -0700415 request.result = true;
416 notifyRequester(request);
417 return;
418 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700419
Pengquan Menga1bb6272018-09-06 09:59:22 -0700420 try {
421 request.result = phone != null
422 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
423 } catch (CallStateException cse) {
424 request.result = false;
425 }
426 // Wake up the requesting thread
427 notifyRequester(request);
428 break;
pkanwar32d516d2016-10-14 19:37:38 -0700429 }
430
Yorke Lee716f67e2015-06-17 15:39:16 -0700431 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700432 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700433 final Phone phone = getPhoneFromRequest(request);
434 request.result = phone != null ?
435 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
436 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700437 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700438 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700439 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700440 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700441
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700442 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700443 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700444 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800445 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700446 if (uiccCard == null) {
447 loge("iccTransmitApduLogicalChannel: No UICC");
448 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700449 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700450 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700451 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
452 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700453 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700454 iccArgument.channel, iccArgument.cla, iccArgument.command,
455 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700456 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700457 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700458 break;
459
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700460 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700461 ar = (AsyncResult) msg.obj;
462 request = (MainThreadRequest) ar.userObj;
463 if (ar.exception == null && ar.result != null) {
464 request.result = ar.result;
465 } else {
466 request.result = new IccIoResult(0x6F, 0, (byte[])null);
467 if (ar.result == null) {
468 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800469 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700470 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800471 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700472 } else {
473 loge("iccTransmitApduLogicalChannel: Unknown exception");
474 }
475 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700476 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700477 break;
478
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700479 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
480 request = (MainThreadRequest) msg.obj;
481 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800482 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700483 if (uiccCard == null) {
484 loge("iccTransmitApduBasicChannel: No UICC");
485 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700486 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700487 } else {
488 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
489 request);
490 uiccCard.iccTransmitApduBasicChannel(
491 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
492 iccArgument.p3, iccArgument.data, onCompleted);
493 }
494 break;
495
496 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
497 ar = (AsyncResult) msg.obj;
498 request = (MainThreadRequest) ar.userObj;
499 if (ar.exception == null && ar.result != null) {
500 request.result = ar.result;
501 } else {
502 request.result = new IccIoResult(0x6F, 0, (byte[])null);
503 if (ar.result == null) {
504 loge("iccTransmitApduBasicChannel: Empty response");
505 } else if (ar.exception instanceof CommandException) {
506 loge("iccTransmitApduBasicChannel: CommandException: " +
507 ar.exception);
508 } else {
509 loge("iccTransmitApduBasicChannel: Unknown exception");
510 }
511 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700512 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700513 break;
514
515 case CMD_EXCHANGE_SIM_IO:
516 request = (MainThreadRequest) msg.obj;
517 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800518 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700519 if (uiccCard == null) {
520 loge("iccExchangeSimIO: No UICC");
521 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700522 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700523 } else {
524 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
525 request);
526 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
527 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
528 iccArgument.data, onCompleted);
529 }
530 break;
531
532 case EVENT_EXCHANGE_SIM_IO_DONE:
533 ar = (AsyncResult) msg.obj;
534 request = (MainThreadRequest) ar.userObj;
535 if (ar.exception == null && ar.result != null) {
536 request.result = ar.result;
537 } else {
538 request.result = new IccIoResult(0x6f, 0, (byte[])null);
539 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700540 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700541 break;
542
Derek Tan4d5e5c12014-02-04 11:54:58 -0800543 case CMD_SEND_ENVELOPE:
544 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800545 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700546 if (uiccCard == null) {
547 loge("sendEnvelopeWithStatus: No UICC");
548 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700549 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700550 } else {
551 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
552 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
553 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800554 break;
555
556 case EVENT_SEND_ENVELOPE_DONE:
557 ar = (AsyncResult) msg.obj;
558 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700559 if (ar.exception == null && ar.result != null) {
560 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800561 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700562 request.result = new IccIoResult(0x6F, 0, (byte[])null);
563 if (ar.result == null) {
564 loge("sendEnvelopeWithStatus: Empty response");
565 } else if (ar.exception instanceof CommandException) {
566 loge("sendEnvelopeWithStatus: CommandException: " +
567 ar.exception);
568 } else {
569 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
570 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800571 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700572 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800573 break;
574
Shishir Agrawal566b7612013-10-28 14:41:00 -0700575 case CMD_OPEN_CHANNEL:
576 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800577 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800578 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700579 if (uiccCard == null) {
580 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800581 request.result = new IccOpenLogicalChannelResponse(-1,
582 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700583 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700584 } else {
585 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800586 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
587 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700588 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700589 break;
590
591 case EVENT_OPEN_CHANNEL_DONE:
592 ar = (AsyncResult) msg.obj;
593 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700594 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700595 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700596 int[] result = (int[]) ar.result;
597 int channelId = result[0];
598 byte[] selectResponse = null;
599 if (result.length > 1) {
600 selectResponse = new byte[result.length - 1];
601 for (int i = 1; i < result.length; ++i) {
602 selectResponse[i - 1] = (byte) result[i];
603 }
604 }
605 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700606 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700607 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700608 if (ar.result == null) {
609 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700610 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700611 if (ar.exception != null) {
612 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
613 }
614
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700615 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700616 if (ar.exception instanceof CommandException) {
617 CommandException.Error error =
618 ((CommandException) (ar.exception)).getCommandError();
619 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700620 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700621 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700622 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700623 }
624 }
625 openChannelResp = new IccOpenLogicalChannelResponse(
626 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700627 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700628 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700629 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700630 break;
631
632 case CMD_CLOSE_CHANNEL:
633 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800634 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700635 if (uiccCard == null) {
636 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900637 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700638 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700639 } else {
640 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
641 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
642 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700643 break;
644
645 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800646 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
647 break;
648
649 case CMD_NV_READ_ITEM:
650 request = (MainThreadRequest) msg.obj;
651 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800652 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
653 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800654 break;
655
656 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700657 ar = (AsyncResult) msg.obj;
658 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800659 if (ar.exception == null && ar.result != null) {
660 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700661 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800662 request.result = "";
663 if (ar.result == null) {
664 loge("nvReadItem: Empty response");
665 } else if (ar.exception instanceof CommandException) {
666 loge("nvReadItem: CommandException: " +
667 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700668 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800669 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700670 }
671 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700672 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700673 break;
674
Jake Hambye994d462014-02-03 13:10:13 -0800675 case CMD_NV_WRITE_ITEM:
676 request = (MainThreadRequest) msg.obj;
677 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
678 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800679 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700680 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800681 break;
682
683 case EVENT_NV_WRITE_ITEM_DONE:
684 handleNullReturnEvent(msg, "nvWriteItem");
685 break;
686
687 case CMD_NV_WRITE_CDMA_PRL:
688 request = (MainThreadRequest) msg.obj;
689 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800690 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800691 break;
692
693 case EVENT_NV_WRITE_CDMA_PRL_DONE:
694 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
695 break;
696
chen xu6dac5ab2018-10-26 17:39:23 -0700697 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800698 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700699 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800700 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800701 break;
702
chen xu6dac5ab2018-10-26 17:39:23 -0700703 case EVENT_RESET_MODEM_CONFIG_DONE:
704 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800705 break;
706
Jake Hamby7c27be32014-03-03 13:25:59 -0800707 case CMD_GET_PREFERRED_NETWORK_TYPE:
708 request = (MainThreadRequest) msg.obj;
709 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700710 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800711 break;
712
713 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
714 ar = (AsyncResult) msg.obj;
715 request = (MainThreadRequest) ar.userObj;
716 if (ar.exception == null && ar.result != null) {
717 request.result = ar.result; // Integer
718 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800719 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800720 if (ar.result == null) {
721 loge("getPreferredNetworkType: Empty response");
722 } else if (ar.exception instanceof CommandException) {
723 loge("getPreferredNetworkType: CommandException: " +
724 ar.exception);
725 } else {
726 loge("getPreferredNetworkType: Unknown exception");
727 }
728 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700729 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800730 break;
731
732 case CMD_SET_PREFERRED_NETWORK_TYPE:
733 request = (MainThreadRequest) msg.obj;
734 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
735 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700736 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800737 break;
738
739 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
740 handleNullReturnEvent(msg, "setPreferredNetworkType");
741 break;
742
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000743 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
744 request = (MainThreadRequest)msg.obj;
745 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800746 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000747 break;
748
749 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
750 ar = (AsyncResult)msg.obj;
751 request = (MainThreadRequest)ar.userObj;
752 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700753 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000754 break;
755
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800756 case CMD_SET_VOICEMAIL_NUMBER:
757 request = (MainThreadRequest) msg.obj;
758 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
759 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800760 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
761 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800762 break;
763
764 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
765 handleNullReturnEvent(msg, "setVoicemailNumber");
766 break;
767
Stuart Scott54788802015-03-30 13:18:01 -0700768 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
769 request = (MainThreadRequest) msg.obj;
770 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
771 request);
772 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
773 break;
774
775 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
776 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
777 break;
778
Shishir Agrawal302c8692015-06-19 13:49:39 -0700779 case CMD_PERFORM_NETWORK_SCAN:
780 request = (MainThreadRequest) msg.obj;
781 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
782 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
783 break;
784
785 case EVENT_PERFORM_NETWORK_SCAN_DONE:
786 ar = (AsyncResult) msg.obj;
787 request = (MainThreadRequest) ar.userObj;
788 CellNetworkScanResult cellScanResult;
789 if (ar.exception == null && ar.result != null) {
790 cellScanResult = new CellNetworkScanResult(
791 CellNetworkScanResult.STATUS_SUCCESS,
792 (List<OperatorInfo>) ar.result);
793 } else {
794 if (ar.result == null) {
795 loge("getCellNetworkScanResults: Empty response");
796 }
797 if (ar.exception != null) {
798 loge("getCellNetworkScanResults: Exception: " + ar.exception);
799 }
800 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
801 if (ar.exception instanceof CommandException) {
802 CommandException.Error error =
803 ((CommandException) (ar.exception)).getCommandError();
804 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
805 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
806 } else if (error == CommandException.Error.GENERIC_FAILURE) {
807 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
808 }
809 }
810 cellScanResult = new CellNetworkScanResult(errorCode, null);
811 }
812 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700813 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700814 break;
815
816 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
817 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700818 ManualNetworkSelectionArgument selArg =
819 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700820 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
821 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700822 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
823 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700824 break;
825
826 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700827 ar = (AsyncResult) msg.obj;
828 request = (MainThreadRequest) ar.userObj;
829 if (ar.exception == null) {
830 request.result = true;
831 } else {
832 request.result = false;
833 loge("setNetworkSelectionModeManual " + ar.exception);
834 }
835 notifyRequester(request);
836 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700837 break;
838
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700839 case CMD_GET_MODEM_ACTIVITY_INFO:
840 request = (MainThreadRequest) msg.obj;
841 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -0700842 if (defaultPhone != null) {
843 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
844 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700845 break;
846
847 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
848 ar = (AsyncResult) msg.obj;
849 request = (MainThreadRequest) ar.userObj;
850 if (ar.exception == null && ar.result != null) {
851 request.result = ar.result;
852 } else {
853 if (ar.result == null) {
854 loge("queryModemActivityInfo: Empty response");
855 } else if (ar.exception instanceof CommandException) {
856 loge("queryModemActivityInfo: CommandException: " +
857 ar.exception);
858 } else {
859 loge("queryModemActivityInfo: Unknown exception");
860 }
861 }
Amit Mahajand4766222016-01-28 15:28:28 -0800862 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
863 if (request.result == null) {
864 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
865 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700866 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700867 break;
868
Meng Wang1a7c35a2016-05-05 20:56:15 -0700869 case CMD_SET_ALLOWED_CARRIERS:
870 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -0800871 CarrierRestrictionRules argument =
872 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700873 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -0800874 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700875 break;
876
877 case EVENT_SET_ALLOWED_CARRIERS_DONE:
878 ar = (AsyncResult) msg.obj;
879 request = (MainThreadRequest) ar.userObj;
880 if (ar.exception == null && ar.result != null) {
881 request.result = ar.result;
882 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800883 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
884 if (ar.exception instanceof CommandException) {
885 loge("setAllowedCarriers: CommandException: " + ar.exception);
886 CommandException.Error error =
887 ((CommandException) (ar.exception)).getCommandError();
888 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
889 request.result =
890 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
891 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700892 } else {
893 loge("setAllowedCarriers: Unknown exception");
894 }
895 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700896 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700897 break;
898
899 case CMD_GET_ALLOWED_CARRIERS:
900 request = (MainThreadRequest) msg.obj;
901 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800902 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700903 break;
904
905 case EVENT_GET_ALLOWED_CARRIERS_DONE:
906 ar = (AsyncResult) msg.obj;
907 request = (MainThreadRequest) ar.userObj;
908 if (ar.exception == null && ar.result != null) {
909 request.result = ar.result;
910 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800911 request.result = new IllegalStateException(
912 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700913 if (ar.result == null) {
914 loge("getAllowedCarriers: Empty response");
915 } else if (ar.exception instanceof CommandException) {
916 loge("getAllowedCarriers: CommandException: " +
917 ar.exception);
918 } else {
919 loge("getAllowedCarriers: Unknown exception");
920 }
921 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700922 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700923 break;
924
Nathan Haroldb3014052017-01-25 15:57:32 -0800925 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
926 ar = (AsyncResult) msg.obj;
927 request = (MainThreadRequest) ar.userObj;
928 if (ar.exception == null && ar.result != null) {
929 request.result = ar.result;
930 } else {
931 request.result = new IllegalArgumentException(
932 "Failed to retrieve Forbidden Plmns");
933 if (ar.result == null) {
934 loge("getForbiddenPlmns: Empty response");
935 } else {
936 loge("getForbiddenPlmns: Unknown exception");
937 }
938 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700939 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800940 break;
941
942 case CMD_GET_FORBIDDEN_PLMNS:
943 request = (MainThreadRequest) msg.obj;
944 uiccCard = getUiccCardFromRequest(request);
945 if (uiccCard == null) {
946 loge("getForbiddenPlmns() UiccCard is null");
947 request.result = new IllegalArgumentException(
948 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700949 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800950 break;
951 }
952 Integer appType = (Integer) request.argument;
953 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
954 if (uiccApp == null) {
955 loge("getForbiddenPlmns() no app with specified type -- "
956 + appType);
957 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700958 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800959 break;
960 } else {
961 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
962 + " specified type -- " + appType);
963 }
964 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
965 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
966 onCompleted);
967 break;
968
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000969 case CMD_SWITCH_SLOTS:
970 request = (MainThreadRequest) msg.obj;
971 int[] physicalSlots = (int[]) request.argument;
972 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
973 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
974 break;
975
976 case EVENT_SWITCH_SLOTS_DONE:
977 ar = (AsyncResult) msg.obj;
978 request = (MainThreadRequest) ar.userObj;
979 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700980 notifyRequester(request);
981 break;
982 case CMD_GET_NETWORK_SELECTION_MODE:
983 request = (MainThreadRequest) msg.obj;
984 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
985 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
986 break;
987
988 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
989 ar = (AsyncResult) msg.obj;
990 request = (MainThreadRequest) ar.userObj;
991 if (ar.exception != null) {
992 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
993 } else {
994 int mode = ((int[]) ar.result)[0];
995 if (mode == 0) {
996 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
997 } else {
998 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
999 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001000 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001001 notifyRequester(request);
1002 break;
1003 case CMD_GET_CDMA_ROAMING_MODE:
1004 request = (MainThreadRequest) msg.obj;
1005 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1006 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1007 break;
1008 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1009 ar = (AsyncResult) msg.obj;
1010 request = (MainThreadRequest) ar.userObj;
1011 if (ar.exception != null) {
1012 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1013 } else {
1014 request.result = ((int[]) ar.result)[0];
1015 }
1016 notifyRequester(request);
1017 break;
1018 case CMD_SET_CDMA_ROAMING_MODE:
1019 request = (MainThreadRequest) msg.obj;
1020 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1021 int mode = (int) request.argument;
1022 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1023 break;
1024 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1025 ar = (AsyncResult) msg.obj;
1026 request = (MainThreadRequest) ar.userObj;
1027 request.result = ar.exception == null;
1028 notifyRequester(request);
1029 break;
1030 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1031 request = (MainThreadRequest) msg.obj;
1032 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1033 int subscriptionMode = (int) request.argument;
1034 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1035 break;
1036 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1037 ar = (AsyncResult) msg.obj;
1038 request = (MainThreadRequest) ar.userObj;
1039 request.result = ar.exception == null;
1040 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001041 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001042 case CMD_GET_ALL_CELL_INFO:
1043 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001044 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001045 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001046 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001047 case EVENT_GET_ALL_CELL_INFO_DONE:
1048 ar = (AsyncResult) msg.obj;
1049 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001050 // If a timeout occurs, the response will be null
1051 request.result = (ar.exception == null && ar.result != null)
1052 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001053 synchronized (request) {
1054 request.notifyAll();
1055 }
1056 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001057 case CMD_REQUEST_CELL_INFO_UPDATE:
1058 request = (MainThreadRequest) msg.obj;
1059 request.phone.requestCellInfoUpdate(request.workSource,
1060 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1061 break;
1062 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1063 ar = (AsyncResult) msg.obj;
1064 request = (MainThreadRequest) ar.userObj;
1065 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1066 try {
1067 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001068 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Nathan Harolde82c4b82018-12-18 19:40:37 -08001069 cb.onError(TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1070 new android.os.ParcelableException(ar.exception));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001071 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001072 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Nathan Harolde82c4b82018-12-18 19:40:37 -08001073 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001074 } else {
1075 // use the result as returned
1076 cb.onCellInfo((List<CellInfo>) ar.result);
1077 }
1078 } catch (RemoteException re) {
1079 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1080 }
1081 break;
1082 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001083 request = (MainThreadRequest) msg.obj;
1084 WorkSource ws = (WorkSource) request.argument;
1085 Phone phone = getPhoneFromRequest(request);
1086 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1087 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001088 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001089 ar = (AsyncResult) msg.obj;
1090 request = (MainThreadRequest) ar.userObj;
1091 if (ar.exception == null) {
1092 request.result = ar.result;
1093 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001094 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001095 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1096 ? new CdmaCellLocation() : new GsmCellLocation();
1097 }
1098
1099 synchronized (request) {
1100 request.notifyAll();
1101 }
1102 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001103 case CMD_MODEM_REBOOT:
1104 request = (MainThreadRequest) msg.obj;
1105 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001106 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001107 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001108 case EVENT_CMD_MODEM_REBOOT_DONE:
1109 handleNullReturnEvent(msg, "rebootModem");
1110 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001111 case CMD_REQUEST_ENABLE_MODEM:
1112 request = (MainThreadRequest) msg.obj;
1113 boolean enable = (boolean) request.argument;
1114 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001115 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001116 PhoneConfigurationManager.getInstance()
1117 .enablePhone(request.phone, enable, onCompleted);
1118 break;
1119 case EVENT_ENABLE_MODEM_DONE:
1120 ar = (AsyncResult) msg.obj;
1121 request = (MainThreadRequest) ar.userObj;
1122 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001123 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001124 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001125 if ((boolean) request.result) {
1126 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1127 updateModemStateMetrics();
1128 } else {
1129 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1130 + ar.exception);
1131 }
1132 notifyRequester(request);
1133 break;
1134 case CMD_GET_MODEM_STATUS:
1135 request = (MainThreadRequest) msg.obj;
1136 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1137 PhoneConfigurationManager.getInstance()
1138 .getPhoneStatusFromModem(request.phone, onCompleted);
1139 break;
1140 case EVENT_GET_MODEM_STATUS_DONE:
1141 ar = (AsyncResult) msg.obj;
1142 request = (MainThreadRequest) ar.userObj;
1143 int id = request.phone.getPhoneId();
1144 if (ar.exception == null && ar.result != null) {
1145 request.result = ar.result;
1146 //update the cache as modem status has changed
1147 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1148 (boolean) request.result);
1149 } else {
1150 // Return true if modem status cannot be retrieved. For most cases,
1151 // modem status is on. And for older version modems, GET_MODEM_STATUS
1152 // and disable modem are not supported. Modem is always on.
1153 // TODO: this should be fixed in R to support a third
1154 // status UNKNOWN b/131631629
1155 request.result = true;
1156 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1157 + ar.exception);
1158 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001159 notifyRequester(request);
1160 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001161 default:
1162 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1163 break;
1164 }
1165 }
Jake Hambye994d462014-02-03 13:10:13 -08001166
Pengquan Menga1bb6272018-09-06 09:59:22 -07001167 private void notifyRequester(MainThreadRequest request) {
1168 synchronized (request) {
1169 request.notifyAll();
1170 }
1171 }
1172
Jake Hambye994d462014-02-03 13:10:13 -08001173 private void handleNullReturnEvent(Message msg, String command) {
1174 AsyncResult ar = (AsyncResult) msg.obj;
1175 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1176 if (ar.exception == null) {
1177 request.result = true;
1178 } else {
1179 request.result = false;
1180 if (ar.exception instanceof CommandException) {
1181 loge(command + ": CommandException: " + ar.exception);
1182 } else {
1183 loge(command + ": Unknown exception");
1184 }
1185 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001186 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001187 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001188 }
1189
1190 /**
1191 * Posts the specified command to be executed on the main thread,
1192 * waits for the request to complete, and returns the result.
1193 * @see #sendRequestAsync
1194 */
1195 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001196 return sendRequest(
1197 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001198 }
1199
1200 /**
1201 * Posts the specified command to be executed on the main thread,
1202 * waits for the request to complete, and returns the result.
1203 * @see #sendRequestAsync
1204 */
1205 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1206 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001207 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001208 }
1209
1210 /**
1211 * Posts the specified command to be executed on the main thread,
1212 * waits for the request to complete, and returns the result.
1213 * @see #sendRequestAsync
1214 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001215 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001216 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001217 }
1218
1219 /**
1220 * Posts the specified command to be executed on the main thread,
1221 * waits for the request to complete, and returns the result.
1222 * @see #sendRequestAsync
1223 */
Nathan Harold92bed182018-10-12 18:16:49 -07001224 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1225 return sendRequest(command, argument, subId, null, workSource);
1226 }
1227
1228 /**
1229 * Posts the specified command to be executed on the main thread,
1230 * waits for the request to complete, and returns the result.
1231 * @see #sendRequestAsync
1232 */
1233 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1234 return sendRequest(
1235 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1236 }
1237
1238 /**
1239 * Posts the specified command to be executed on the main thread,
1240 * waits for the request to complete, and returns the result.
1241 * @see #sendRequestAsync
1242 */
1243 private Object sendRequest(
1244 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001245 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1246 throw new RuntimeException("This method will deadlock if called from the main thread.");
1247 }
1248
Nathan Harold92bed182018-10-12 18:16:49 -07001249 MainThreadRequest request = null;
1250 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1251 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1252 } else if (phone != null) {
1253 request = new MainThreadRequest(argument, phone, workSource);
1254 } else {
1255 request = new MainThreadRequest(argument, subId, workSource);
1256 }
1257
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001258 Message msg = mMainThreadHandler.obtainMessage(command, request);
1259 msg.sendToTarget();
1260
1261 // Wait for the request to complete
1262 synchronized (request) {
1263 while (request.result == null) {
1264 try {
1265 request.wait();
1266 } catch (InterruptedException e) {
1267 // Do nothing, go back and wait until the request is complete
1268 }
1269 }
1270 }
1271 return request.result;
1272 }
1273
1274 /**
1275 * Asynchronous ("fire and forget") version of sendRequest():
1276 * Posts the specified command to be executed on the main thread, and
1277 * returns immediately.
1278 * @see #sendRequest
1279 */
1280 private void sendRequestAsync(int command) {
1281 mMainThreadHandler.sendEmptyMessage(command);
1282 }
1283
1284 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001285 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001286 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001287 */
1288 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001289 sendRequestAsync(command, argument, null, null);
1290 }
1291
1292 /**
1293 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1294 * @see {@link #sendRequest(int,Object)}
1295 */
1296 private void sendRequestAsync(
1297 int command, Object argument, Phone phone, WorkSource workSource) {
1298 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001299 Message msg = mMainThreadHandler.obtainMessage(command, request);
1300 msg.sendToTarget();
1301 }
1302
1303 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001304 * Initialize the singleton PhoneInterfaceManager instance.
1305 * This is only done once, at startup, from PhoneApp.onCreate().
1306 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001307 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001308 synchronized (PhoneInterfaceManager.class) {
1309 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001310 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001311 } else {
1312 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1313 }
1314 return sInstance;
1315 }
1316 }
1317
1318 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001319 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001320 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001321 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001322 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001323 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1324 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001325 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001326 mTelephonySharedPreferences =
1327 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001328 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001329 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001330
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001331 publish();
1332 }
1333
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001334 private Phone getDefaultPhone() {
1335 Phone thePhone = getPhone(getDefaultSubscription());
1336 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1337 }
1338
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001339 private void publish() {
1340 if (DBG) log("publish: " + this);
1341
1342 ServiceManager.addService("phone", this);
1343 }
1344
Stuart Scott584921c2015-01-15 17:10:34 -08001345 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001346 if (request.phone != null) {
1347 return request.phone;
1348 } else {
1349 return getPhoneFromSubId(request.subId);
1350 }
1351 }
1352
1353 private Phone getPhoneFromSubId(int subId) {
1354 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1355 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001356 }
1357
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001358 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1359 Phone phone = getPhoneFromRequest(request);
1360 return phone == null ? null :
1361 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1362 }
1363
Wink Saville36469e72014-06-11 15:17:00 -07001364 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001365 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001366 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001367 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001368
1369 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001370 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001371 }
1372
Wink Savilleb564aae2014-10-23 10:18:09 -07001373 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001374 if (DBG) log("dial: " + number);
1375 // No permission check needed here: This is just a wrapper around the
1376 // ACTION_DIAL intent, which is available to any app since it puts up
1377 // the UI before it does anything.
1378
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001379 final long identity = Binder.clearCallingIdentity();
1380 try {
1381 String url = createTelUrl(number);
1382 if (url == null) {
1383 return;
1384 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001385
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001386 // PENDING: should we just silently fail if phone is offhook or ringing?
1387 PhoneConstants.State state = mCM.getState(subId);
1388 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1389 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1390 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1391 mApp.startActivity(intent);
1392 }
1393 } finally {
1394 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001395 }
1396 }
1397
1398 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001399 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001400 }
1401
Wink Savilleb564aae2014-10-23 10:18:09 -07001402 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001403 if (DBG) log("call: " + number);
1404
1405 // This is just a wrapper around the ACTION_CALL intent, but we still
1406 // need to do a permission check since we're calling startActivity()
1407 // from the context of the phone app.
1408 enforceCallPermission();
1409
1410 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1411 != AppOpsManager.MODE_ALLOWED) {
1412 return;
1413 }
1414
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001415 final long identity = Binder.clearCallingIdentity();
1416 try {
1417 String url = createTelUrl(number);
1418 if (url == null) {
1419 return;
1420 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001421
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001422 boolean isValid = false;
1423 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1424 if (slist != null) {
1425 for (SubscriptionInfo subInfoRecord : slist) {
1426 if (subInfoRecord.getSubscriptionId() == subId) {
1427 isValid = true;
1428 break;
1429 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001430 }
Wink Saville08874612014-08-31 19:19:58 -07001431 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001432 if (!isValid) {
1433 return;
1434 }
Wink Saville08874612014-08-31 19:19:58 -07001435
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001436 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1437 intent.putExtra(SUBSCRIPTION_KEY, subId);
1438 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1439 mApp.startActivity(intent);
1440 } finally {
1441 Binder.restoreCallingIdentity(identity);
1442 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001443 }
1444
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001445 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001446 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001447 }
1448
Wink Savilleb564aae2014-10-23 10:18:09 -07001449 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001450 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001451 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1452 }
1453
1454 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001455 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001456 }
1457
Wink Savilleb564aae2014-10-23 10:18:09 -07001458 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001459 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001460 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1461 }
1462
1463 /** {@hide} */
1464 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001465 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001466 }
1467
Wink Savilleb564aae2014-10-23 10:18:09 -07001468 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001469 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001470
1471 final long identity = Binder.clearCallingIdentity();
1472 try {
1473 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1474 checkSimPin.start();
1475 return checkSimPin.unlockSim(null, pin);
1476 } finally {
1477 Binder.restoreCallingIdentity(identity);
1478 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001479 }
1480
Wink Saville9de0f752013-10-22 19:04:03 -07001481 /** {@hide} */
1482 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001483 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001484 }
1485
Wink Savilleb564aae2014-10-23 10:18:09 -07001486 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001487 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001488
1489 final long identity = Binder.clearCallingIdentity();
1490 try {
1491 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1492 checkSimPuk.start();
1493 return checkSimPuk.unlockSim(puk, pin);
1494 } finally {
1495 Binder.restoreCallingIdentity(identity);
1496 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001497 }
1498
1499 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001500 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001501 * a synchronous one.
1502 */
1503 private static class UnlockSim extends Thread {
1504
1505 private final IccCard mSimCard;
1506
1507 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001508 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1509 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001510
1511 // For replies from SimCard interface
1512 private Handler mHandler;
1513
1514 // For async handler to identify request type
1515 private static final int SUPPLY_PIN_COMPLETE = 100;
1516
1517 public UnlockSim(IccCard simCard) {
1518 mSimCard = simCard;
1519 }
1520
1521 @Override
1522 public void run() {
1523 Looper.prepare();
1524 synchronized (UnlockSim.this) {
1525 mHandler = new Handler() {
1526 @Override
1527 public void handleMessage(Message msg) {
1528 AsyncResult ar = (AsyncResult) msg.obj;
1529 switch (msg.what) {
1530 case SUPPLY_PIN_COMPLETE:
1531 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1532 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001533 mRetryCount = msg.arg1;
1534 if (ar.exception != null) {
1535 if (ar.exception instanceof CommandException &&
1536 ((CommandException)(ar.exception)).getCommandError()
1537 == CommandException.Error.PASSWORD_INCORRECT) {
1538 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1539 } else {
1540 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1541 }
1542 } else {
1543 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1544 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001545 mDone = true;
1546 UnlockSim.this.notifyAll();
1547 }
1548 break;
1549 }
1550 }
1551 };
1552 UnlockSim.this.notifyAll();
1553 }
1554 Looper.loop();
1555 }
1556
1557 /*
1558 * Use PIN or PUK to unlock SIM card
1559 *
1560 * If PUK is null, unlock SIM card with PIN
1561 *
1562 * If PUK is not null, unlock SIM card with PUK and set PIN code
1563 */
Wink Saville9de0f752013-10-22 19:04:03 -07001564 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001565
1566 while (mHandler == null) {
1567 try {
1568 wait();
1569 } catch (InterruptedException e) {
1570 Thread.currentThread().interrupt();
1571 }
1572 }
1573 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1574
1575 if (puk == null) {
1576 mSimCard.supplyPin(pin, callback);
1577 } else {
1578 mSimCard.supplyPuk(puk, pin, callback);
1579 }
1580
1581 while (!mDone) {
1582 try {
1583 Log.d(LOG_TAG, "wait for done");
1584 wait();
1585 } catch (InterruptedException e) {
1586 // Restore the interrupted status
1587 Thread.currentThread().interrupt();
1588 }
1589 }
1590 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001591 int[] resultArray = new int[2];
1592 resultArray[0] = mResult;
1593 resultArray[1] = mRetryCount;
1594 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001595 }
1596 }
1597
1598 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001599 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001600
1601 }
1602
Wink Savilleb564aae2014-10-23 10:18:09 -07001603 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001604 // No permission check needed here: this call is harmless, and it's
1605 // needed for the ServiceState.requestStateUpdate() call (which is
1606 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001607 final long identity = Binder.clearCallingIdentity();
1608 try {
1609 final Phone phone = getPhone(subId);
1610 if (phone != null) {
1611 phone.updateServiceLocation();
1612 }
1613 } finally {
1614 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001615 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001616 }
1617
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001618 @Override
1619 public boolean isRadioOn(String callingPackage) {
1620 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001621 }
1622
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001623 @Override
1624 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001625 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001626 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001627 return false;
1628 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001629
1630 final long identity = Binder.clearCallingIdentity();
1631 try {
1632 return isRadioOnForSubscriber(subId);
1633 } finally {
1634 Binder.restoreCallingIdentity(identity);
1635 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001636 }
1637
1638 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001639 final long identity = Binder.clearCallingIdentity();
1640 try {
1641 final Phone phone = getPhone(subId);
1642 if (phone != null) {
1643 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1644 } else {
1645 return false;
1646 }
1647 } finally {
1648 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001649 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001650 }
1651
1652 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001653 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001654 }
Wink Saville36469e72014-06-11 15:17:00 -07001655
Wink Savilleb564aae2014-10-23 10:18:09 -07001656 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001657 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001658
1659 final long identity = Binder.clearCallingIdentity();
1660 try {
1661 final Phone phone = getPhone(subId);
1662 if (phone != null) {
1663 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1664 }
1665 } finally {
1666 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001667 }
Wink Saville36469e72014-06-11 15:17:00 -07001668 }
1669
1670 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001671 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001672 }
1673
Wink Savilleb564aae2014-10-23 10:18:09 -07001674 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001675 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001676
1677 final long identity = Binder.clearCallingIdentity();
1678 try {
1679 final Phone phone = getPhone(subId);
1680 if (phone == null) {
1681 return false;
1682 }
1683 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1684 toggleRadioOnOffForSubscriber(subId);
1685 }
1686 return true;
1687 } finally {
1688 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001689 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001690 }
Wink Saville36469e72014-06-11 15:17:00 -07001691
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001692 public boolean needMobileRadioShutdown() {
1693 /*
1694 * If any of the Radios are available, it will need to be
1695 * shutdown. So return true if any Radio is available.
1696 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001697 final long identity = Binder.clearCallingIdentity();
1698 try {
1699 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1700 Phone phone = PhoneFactory.getPhone(i);
1701 if (phone != null && phone.isRadioAvailable()) return true;
1702 }
1703 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1704 return false;
1705 } finally {
1706 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001707 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001708 }
1709
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001710 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001711 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001712 enforceModifyPermission();
1713
1714 final long identity = Binder.clearCallingIdentity();
1715 try {
1716 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1717 logv("Shutting down Phone " + i);
1718 shutdownRadioUsingPhoneId(i);
1719 }
1720 } finally {
1721 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001722 }
1723 }
1724
1725 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001726 Phone phone = PhoneFactory.getPhone(phoneId);
1727 if (phone != null && phone.isRadioAvailable()) {
1728 phone.shutdownRadio();
1729 }
1730 }
1731
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001732 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001733 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001734
1735 final long identity = Binder.clearCallingIdentity();
1736 try {
1737 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1738 if (defaultPhone != null) {
1739 defaultPhone.setRadioPower(turnOn);
1740 return true;
1741 } else {
1742 loge("There's no default phone.");
1743 return false;
1744 }
1745 } finally {
1746 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001747 }
Wink Saville36469e72014-06-11 15:17:00 -07001748 }
1749
Wink Savilleb564aae2014-10-23 10:18:09 -07001750 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001751 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001752
1753 final long identity = Binder.clearCallingIdentity();
1754 try {
1755 final Phone phone = getPhone(subId);
1756 if (phone != null) {
1757 phone.setRadioPower(turnOn);
1758 return true;
1759 } else {
1760 return false;
1761 }
1762 } finally {
1763 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001764 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001765 }
1766
Wink Saville36469e72014-06-11 15:17:00 -07001767 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001768 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001769 public boolean enableDataConnectivity() {
1770 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001771
1772 final long identity = Binder.clearCallingIdentity();
1773 try {
1774 int subId = mSubscriptionController.getDefaultDataSubId();
1775 final Phone phone = getPhone(subId);
1776 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001777 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001778 return true;
1779 } else {
1780 return false;
1781 }
1782 } finally {
1783 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001784 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001785 }
1786
Wink Saville36469e72014-06-11 15:17:00 -07001787 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001788 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001789 public boolean disableDataConnectivity() {
1790 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001791
1792 final long identity = Binder.clearCallingIdentity();
1793 try {
1794 int subId = mSubscriptionController.getDefaultDataSubId();
1795 final Phone phone = getPhone(subId);
1796 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001797 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001798 return true;
1799 } else {
1800 return false;
1801 }
1802 } finally {
1803 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001804 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001805 }
1806
Sanket Padawe356d7632015-06-22 14:03:32 -07001807 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001808 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001809 final long identity = Binder.clearCallingIdentity();
1810 try {
1811 final Phone phone = getPhone(subId);
1812 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001813 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001814 } else {
1815 return false;
1816 }
1817 } finally {
1818 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001819 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001820 }
1821
1822 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001823 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001824 }
1825
pkanwarae03a6b2016-11-06 20:37:09 -08001826 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001827 enforceCallPermission();
1828
1829 final long identity = Binder.clearCallingIdentity();
1830 try {
1831 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1832 return;
1833 }
1834 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1835 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1836 } finally {
1837 Binder.restoreCallingIdentity(identity);
1838 }
pkanwar32d516d2016-10-14 19:37:38 -07001839 };
1840
Wink Savilleb564aae2014-10-23 10:18:09 -07001841 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001842 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001843
1844 final long identity = Binder.clearCallingIdentity();
1845 try {
1846 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1847 return false;
1848 }
1849 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1850 } finally {
1851 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001852 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001853 }
1854
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001855 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001856 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001857 }
1858
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001859 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001860 final long identity = Binder.clearCallingIdentity();
1861 try {
1862 Phone phone = PhoneFactory.getPhone(slotIndex);
1863 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1864 PhoneConstantConversions.convertCallState(phone.getState());
1865 } finally {
1866 Binder.restoreCallingIdentity(identity);
1867 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001868 }
1869
Sanket Padawe356d7632015-06-22 14:03:32 -07001870 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001871 public int getDataState() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001872 final long identity = Binder.clearCallingIdentity();
1873 try {
1874 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1875 if (phone != null) {
1876 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1877 } else {
1878 return PhoneConstantConversions.convertDataState(
1879 PhoneConstants.DataState.DISCONNECTED);
1880 }
1881 } finally {
1882 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001883 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001884 }
1885
Sanket Padawe356d7632015-06-22 14:03:32 -07001886 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001887 public int getDataActivity() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001888 final long identity = Binder.clearCallingIdentity();
1889 try {
1890 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1891 if (phone != null) {
1892 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1893 } else {
1894 return TelephonyManager.DATA_ACTIVITY_NONE;
1895 }
1896 } finally {
1897 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001898 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001899 }
1900
1901 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001902 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001903 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001904 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08001905
1906 LocationAccessPolicy.LocationPermissionResult locationResult =
1907 LocationAccessPolicy.checkLocationPermission(mApp,
1908 new LocationAccessPolicy.LocationPermissionQuery.Builder()
1909 .setCallingPackage(callingPackage)
1910 .setCallingPid(Binder.getCallingPid())
1911 .setCallingUid(Binder.getCallingUid())
1912 .setMethod("getCellLocation")
1913 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
1914 .build());
1915 switch (locationResult) {
1916 case DENIED_HARD:
1917 throw new SecurityException("Not allowed to access cell location");
1918 case DENIED_SOFT:
1919 return new Bundle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001920 }
1921
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001922 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001923 final long identity = Binder.clearCallingIdentity();
1924 try {
1925 if (DBG_LOC) log("getCellLocation: is active user");
1926 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001927 int subId = mSubscriptionController.getDefaultDataSubId();
1928 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1929 cl.fillInNotifierBundle(data);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001930 return data;
1931 } finally {
1932 Binder.restoreCallingIdentity(identity);
1933 }
Svetoslav64fad262015-04-14 14:35:21 -07001934 }
1935
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001936 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001937 public String getNetworkCountryIsoForPhone(int phoneId) {
1938 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1939 // registered cell info, so return a NULL country instead.
1940 final long identity = Binder.clearCallingIdentity();
1941 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001942 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1943 // Get default phone in this case.
1944 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1945 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001946 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001947 // Todo: fix this when we can get the actual cellular network info when the device
1948 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001949 if (TelephonyManager.NETWORK_TYPE_IWLAN
1950 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1951 return "";
1952 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001953 Phone phone = PhoneFactory.getPhone(phoneId);
1954 if (phone != null) {
1955 ServiceStateTracker sst = phone.getServiceStateTracker();
1956 if (sst != null) {
1957 LocaleTracker lt = sst.getLocaleTracker();
1958 if (lt != null) {
1959 return lt.getCurrentCountry();
1960 }
1961 }
1962 }
1963 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001964 } finally {
1965 Binder.restoreCallingIdentity(identity);
1966 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001967 }
1968
1969 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001970 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001971 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001972 }
1973
Sanket Padawe356d7632015-06-22 14:03:32 -07001974 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001975 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001976 mApp.enforceCallingOrSelfPermission(
1977 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001978
1979 final long identity = Binder.clearCallingIdentity();
1980 try {
1981 final Phone phone = getPhone(subId);
1982 if (phone != null) {
1983 phone.enableLocationUpdates();
1984 }
1985 } finally {
1986 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001987 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001988 }
1989
1990 @Override
1991 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001992 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001993 }
1994
Sanket Padawe356d7632015-06-22 14:03:32 -07001995 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001996 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001997 mApp.enforceCallingOrSelfPermission(
1998 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001999
2000 final long identity = Binder.clearCallingIdentity();
2001 try {
2002 final Phone phone = getPhone(subId);
2003 if (phone != null) {
2004 phone.disableLocationUpdates();
2005 }
2006 } finally {
2007 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002008 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002009 }
2010
Nathan Harold31d7ff32018-10-15 20:20:30 -07002011 /**
2012 * Returns the target SDK version number for a given package name.
2013 *
2014 * @return target SDK if the package is found or INT_MAX.
2015 */
2016 private int getTargetSdk(String packageName) {
2017 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002018 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(
2019 packageName, 0);
Nathan Harold31d7ff32018-10-15 20:20:30 -07002020 if (ai != null) return ai.targetSdkVersion;
2021 } catch (PackageManager.NameNotFoundException unexpected) {
2022 }
2023 return Integer.MAX_VALUE;
2024 }
2025
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002026 @Override
2027 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07002028 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
2029 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002030 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2031 throw new SecurityException(
2032 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2033 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002034
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002035 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
2036 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2037 return null;
2038 }
Svetoslav64fad262015-04-14 14:35:21 -07002039
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002040 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002041
Nathan Haroldf180aac2018-06-01 18:43:55 -07002042 List<CellInfo> info = getAllCellInfo(callingPackage);
2043 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002044
Nathan Haroldf180aac2018-06-01 18:43:55 -07002045 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2046 for (CellInfo ci : info) {
2047 if (ci instanceof CellInfoGsm) {
2048 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2049 } else if (ci instanceof CellInfoWcdma) {
2050 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2051 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002052 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002053 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002054 }
2055
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002056 private List<CellInfo> getCachedCellInfo() {
2057 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2058 for (Phone phone : PhoneFactory.getPhones()) {
2059 List<CellInfo> info = phone.getAllCellInfo();
2060 if (info != null) cellInfos.addAll(info);
2061 }
2062 return cellInfos;
2063 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002064
2065 @Override
Svetoslav64fad262015-04-14 14:35:21 -07002066 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002067 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002068 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002069
2070 LocationAccessPolicy.LocationPermissionResult locationResult =
2071 LocationAccessPolicy.checkLocationPermission(mApp,
2072 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2073 .setCallingPackage(callingPackage)
2074 .setCallingPid(Binder.getCallingPid())
2075 .setCallingUid(Binder.getCallingUid())
2076 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002077 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002078 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2079 .build());
2080 switch (locationResult) {
2081 case DENIED_HARD:
2082 throw new SecurityException("Not allowed to access cell info");
2083 case DENIED_SOFT:
2084 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002085 }
2086
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002087 final int targetSdk = getTargetSdk(callingPackage);
2088 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2089 return getCachedCellInfo();
2090 }
2091
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002092 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002093 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002094 final long identity = Binder.clearCallingIdentity();
2095 try {
2096 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2097 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002098 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002099 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002100 if (info != null) cellInfos.addAll(info);
2101 }
2102 return cellInfos;
2103 } finally {
2104 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002105 }
2106 }
2107
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002108 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002109 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2110 requestCellInfoUpdateInternal(
2111 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2112 }
2113
2114 @Override
2115 public void requestCellInfoUpdateWithWorkSource(
2116 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2117 enforceModifyPermission();
2118 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2119 }
2120
2121 private void requestCellInfoUpdateInternal(
2122 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002123 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002124 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002125
2126 LocationAccessPolicy.LocationPermissionResult locationResult =
2127 LocationAccessPolicy.checkLocationPermission(mApp,
2128 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2129 .setCallingPackage(callingPackage)
2130 .setCallingPid(Binder.getCallingPid())
2131 .setCallingUid(Binder.getCallingUid())
2132 .setMethod("requestCellInfoUpdate")
2133 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2134 .build());
2135 switch (locationResult) {
2136 case DENIED_HARD:
2137 throw new SecurityException("Not allowed to access cell info");
2138 case DENIED_SOFT:
2139 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002140 }
2141
2142 final Phone phone = getPhone(subId);
2143 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2144
2145 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2146 }
2147
2148 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002149 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002150 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002151 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002152
2153 final long identity = Binder.clearCallingIdentity();
2154 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002155 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002156 } finally {
2157 Binder.restoreCallingIdentity(identity);
2158 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002159 }
2160
Shishir Agrawala9f32182016-04-12 12:00:16 -07002161 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002162 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002163 Phone phone = PhoneFactory.getPhone(slotIndex);
2164 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002165 return null;
2166 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002167 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002168 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2169 callingPackage, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002170 return null;
2171 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002172
2173 final long identity = Binder.clearCallingIdentity();
2174 try {
2175 return phone.getImei();
2176 } finally {
2177 Binder.restoreCallingIdentity(identity);
2178 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002179 }
2180
2181 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002182 public String getTypeAllocationCodeForSlot(int slotIndex) {
2183 Phone phone = PhoneFactory.getPhone(slotIndex);
2184 String tac = null;
2185 if (phone != null) {
2186 String imei = phone.getImei();
2187 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2188 }
2189 return tac;
2190 }
2191
2192 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002193 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002194 Phone phone = PhoneFactory.getPhone(slotIndex);
2195 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002196 return null;
2197 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002198
Jeff Davidson913390f2018-02-23 17:11:49 -08002199 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002200 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2201 callingPackage, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002202 return null;
2203 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002204
2205 final long identity = Binder.clearCallingIdentity();
2206 try {
2207 return phone.getMeid();
2208 } finally {
2209 Binder.restoreCallingIdentity(identity);
2210 }
Jack Yu2af8d712017-03-15 17:14:14 -07002211 }
2212
2213 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002214 public String getManufacturerCodeForSlot(int slotIndex) {
2215 Phone phone = PhoneFactory.getPhone(slotIndex);
2216 String manufacturerCode = null;
2217 if (phone != null) {
2218 String meid = phone.getMeid();
2219 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2220 }
2221 return manufacturerCode;
2222 }
2223
2224 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002225 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002226 Phone phone = PhoneFactory.getPhone(slotIndex);
2227 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002228 return null;
2229 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002230 int subId = phone.getSubId();
2231 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2232 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2233 return null;
2234 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002235
2236 final long identity = Binder.clearCallingIdentity();
2237 try {
2238 return phone.getDeviceSvn();
2239 } finally {
2240 Binder.restoreCallingIdentity(identity);
2241 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002242 }
2243
fionaxu43304da2017-11-27 22:51:16 -08002244 @Override
2245 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002246 final long identity = Binder.clearCallingIdentity();
2247 try {
2248 final Phone phone = getPhone(subId);
2249 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2250 } finally {
2251 Binder.restoreCallingIdentity(identity);
2252 }
fionaxu43304da2017-11-27 22:51:16 -08002253 }
2254
2255 @Override
2256 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002257 final long identity = Binder.clearCallingIdentity();
2258 try {
2259 final Phone phone = getPhone(subId);
2260 return phone == null ? null : phone.getCarrierName();
2261 } finally {
2262 Binder.restoreCallingIdentity(identity);
2263 }
fionaxu43304da2017-11-27 22:51:16 -08002264 }
2265
calvinpanffe225e2018-11-01 19:43:06 +08002266 @Override
chen xu0026ca62019-03-06 15:28:50 -08002267 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002268 final long identity = Binder.clearCallingIdentity();
2269 try {
2270 final Phone phone = getPhone(subId);
2271 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002272 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002273 } finally {
2274 Binder.restoreCallingIdentity(identity);
2275 }
2276 }
2277
2278 @Override
chen xu0026ca62019-03-06 15:28:50 -08002279 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002280 final long identity = Binder.clearCallingIdentity();
2281 try {
2282 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002283 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002284 } finally {
2285 Binder.restoreCallingIdentity(identity);
2286 }
2287 }
2288
chen xu651eec72018-11-11 19:03:44 -08002289 @Override
chen xu864e11c2018-12-06 22:10:03 -08002290 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2291 if (!isSubscriptionMccMnc) {
2292 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2293 }
chen xu651eec72018-11-11 19:03:44 -08002294 final Phone phone = PhoneFactory.getPhone(slotIndex);
2295 if (phone == null) {
2296 return TelephonyManager.UNKNOWN_CARRIER_ID;
2297 }
2298 final long identity = Binder.clearCallingIdentity();
2299 try {
2300 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2301 } finally {
2302 Binder.restoreCallingIdentity(identity);
2303 }
2304 }
2305
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002306 //
2307 // Internal helper methods.
2308 //
2309
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002310 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002311 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2312 *
2313 * @throws SecurityException if the caller does not have the required permission
2314 */
2315 private void enforceModifyPermission() {
2316 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2317 }
2318
2319 /**
2320 * Make sure the caller has the CALL_PHONE permission.
2321 *
2322 * @throws SecurityException if the caller does not have the required permission
2323 */
2324 private void enforceCallPermission() {
2325 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2326 }
2327
Stuart Scott8eef64f2015-04-08 15:13:54 -07002328 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002329 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002330 "ConnectivityService");
2331 }
2332
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002333 private String createTelUrl(String number) {
2334 if (TextUtils.isEmpty(number)) {
2335 return null;
2336 }
2337
Jake Hambye994d462014-02-03 13:10:13 -08002338 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002339 }
2340
Ihab Awadf9e92732013-12-05 18:02:52 -08002341 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002342 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2343 }
2344
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002345 private static void logv(String msg) {
2346 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2347 }
2348
Ihab Awadf9e92732013-12-05 18:02:52 -08002349 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002350 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2351 }
2352
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002353 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002354 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002355 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002356 }
2357
Sanket Padawe356d7632015-06-22 14:03:32 -07002358 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002359 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002360 final long identity = Binder.clearCallingIdentity();
2361 try {
2362 final Phone phone = PhoneFactory.getPhone(slotIndex);
2363 if (phone == null) {
2364 return PhoneConstants.PHONE_TYPE_NONE;
2365 } else {
2366 return phone.getPhoneType();
2367 }
2368 } finally {
2369 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002370 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002371 }
2372
2373 /**
2374 * Returns the CDMA ERI icon index to display
2375 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002376 @Override
2377 public int getCdmaEriIconIndex(String callingPackage) {
2378 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002379 }
2380
Sanket Padawe356d7632015-06-22 14:03:32 -07002381 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002382 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002383 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002384 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002385 return -1;
2386 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002387
2388 final long identity = Binder.clearCallingIdentity();
2389 try {
2390 final Phone phone = getPhone(subId);
2391 if (phone != null) {
2392 return phone.getCdmaEriIconIndex();
2393 } else {
2394 return -1;
2395 }
2396 } finally {
2397 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002398 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002399 }
2400
2401 /**
2402 * Returns the CDMA ERI icon mode,
2403 * 0 - ON
2404 * 1 - FLASHING
2405 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002406 @Override
2407 public int getCdmaEriIconMode(String callingPackage) {
2408 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002409 }
2410
Sanket Padawe356d7632015-06-22 14:03:32 -07002411 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002412 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002413 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002414 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002415 return -1;
2416 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002417
2418 final long identity = Binder.clearCallingIdentity();
2419 try {
2420 final Phone phone = getPhone(subId);
2421 if (phone != null) {
2422 return phone.getCdmaEriIconMode();
2423 } else {
2424 return -1;
2425 }
2426 } finally {
2427 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002428 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002429 }
2430
2431 /**
2432 * Returns the CDMA ERI text,
2433 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002434 @Override
2435 public String getCdmaEriText(String callingPackage) {
2436 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002437 }
2438
Sanket Padawe356d7632015-06-22 14:03:32 -07002439 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002440 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002441 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002442 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002443 return null;
2444 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002445
2446 final long identity = Binder.clearCallingIdentity();
2447 try {
2448 final Phone phone = getPhone(subId);
2449 if (phone != null) {
2450 return phone.getCdmaEriText();
2451 } else {
2452 return null;
2453 }
2454 } finally {
2455 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002456 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002457 }
2458
2459 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002460 * Returns the CDMA MDN.
2461 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002462 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002463 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002464 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2465 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002466
2467 final long identity = Binder.clearCallingIdentity();
2468 try {
2469 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002470 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002471 return phone.getLine1Number();
2472 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002473 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002474 return null;
2475 }
2476 } finally {
2477 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002478 }
2479 }
2480
2481 /**
2482 * Returns the CDMA MIN.
2483 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002484 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002485 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002486 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2487 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002488
2489 final long identity = Binder.clearCallingIdentity();
2490 try {
2491 final Phone phone = getPhone(subId);
2492 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2493 return phone.getCdmaMin();
2494 } else {
2495 return null;
2496 }
2497 } finally {
2498 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002499 }
2500 }
2501
Hall Liud892bec2018-11-30 14:51:45 -08002502 @Override
2503 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2504 INumberVerificationCallback callback, String callingPackage) {
2505 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2506 != PERMISSION_GRANTED) {
2507 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2508 }
2509 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2510
2511 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2512 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2513 throw new SecurityException("Calling package must be configured in the device config");
2514 }
2515
2516 if (range == null) {
2517 throw new NullPointerException("Range must be non-null");
2518 }
2519
2520 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002521 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002522
2523 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2524 }
2525
Junda Liuca05d5d2014-08-14 22:36:34 -07002526 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002527 * Returns true if CDMA provisioning needs to run.
2528 */
2529 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002530 final long identity = Binder.clearCallingIdentity();
2531 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002532 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002533 } finally {
2534 Binder.restoreCallingIdentity(identity);
2535 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002536 }
2537
2538 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002539 * Sets the voice mail number of a given subId.
2540 */
2541 @Override
2542 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002543 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002544
2545 final long identity = Binder.clearCallingIdentity();
2546 try {
2547 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2548 new Pair<String, String>(alphaTag, number), new Integer(subId));
2549 return success;
2550 } finally {
2551 Binder.restoreCallingIdentity(identity);
2552 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002553 }
2554
Ta-wei Yen87c49842016-05-13 21:19:52 -07002555 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002556 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2557 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002558 String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002559 if (!TextUtils.equals(callingPackage, systemDialer)) {
2560 throw new SecurityException("caller must be system dialer");
2561 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002562
2563 final long identity = Binder.clearCallingIdentity();
2564 try {
2565 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2566 if (phoneAccountHandle == null) {
2567 return null;
2568 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002569 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002570 } finally {
2571 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002572 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002573 }
2574
2575 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002576 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002577 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002578 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002579 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002580 return null;
2581 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002582
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002583 final long identity = Binder.clearCallingIdentity();
2584 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002585 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002586 } finally {
2587 Binder.restoreCallingIdentity(identity);
2588 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002589 }
2590
2591 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002592 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2593 VisualVoicemailSmsFilterSettings settings) {
2594 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002595
2596 final long identity = Binder.clearCallingIdentity();
2597 try {
2598 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002599 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002600 } finally {
2601 Binder.restoreCallingIdentity(identity);
2602 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002603 }
2604
2605 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002606 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2607 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002608
2609 final long identity = Binder.clearCallingIdentity();
2610 try {
2611 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002612 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002613 } finally {
2614 Binder.restoreCallingIdentity(identity);
2615 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002616 }
2617
2618 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002619 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2620 String callingPackage, int subId) {
2621 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002622
2623 final long identity = Binder.clearCallingIdentity();
2624 try {
2625 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002626 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002627 } finally {
2628 Binder.restoreCallingIdentity(identity);
2629 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002630 }
2631
2632 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002633 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002634 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002635
2636 final long identity = Binder.clearCallingIdentity();
2637 try {
2638 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002639 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002640 } finally {
2641 Binder.restoreCallingIdentity(identity);
2642 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002643 }
2644
2645 @Override
2646 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2647 String number, int port, String text, PendingIntent sentIntent) {
2648 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002649 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002650 enforceSendSmsPermission();
2651 // Make the calls as the phone process.
2652 final long identity = Binder.clearCallingIdentity();
2653 try {
2654 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2655 if (port == 0) {
2656 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2657 sentIntent, null, false);
2658 } else {
2659 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2660 smsManager.sendDataMessageWithSelfPermissions(number, null,
2661 (short) port, data, sentIntent, null);
2662 }
2663 } finally {
2664 Binder.restoreCallingIdentity(identity);
2665 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002666 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002667 /**
fionaxu0152e512016-11-14 13:36:14 -08002668 * Sets the voice activation state of a given subId.
2669 */
2670 @Override
2671 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002672 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2673 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002674
2675 final long identity = Binder.clearCallingIdentity();
2676 try {
2677 final Phone phone = getPhone(subId);
2678 if (phone != null) {
2679 phone.setVoiceActivationState(activationState);
2680 } else {
2681 loge("setVoiceActivationState fails with invalid subId: " + subId);
2682 }
2683 } finally {
2684 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002685 }
2686 }
2687
2688 /**
2689 * Sets the data activation state of a given subId.
2690 */
2691 @Override
2692 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002693 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2694 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002695
2696 final long identity = Binder.clearCallingIdentity();
2697 try {
2698 final Phone phone = getPhone(subId);
2699 if (phone != null) {
2700 phone.setDataActivationState(activationState);
2701 } else {
2702 loge("setVoiceActivationState fails with invalid subId: " + subId);
2703 }
2704 } finally {
2705 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002706 }
2707 }
2708
2709 /**
2710 * Returns the voice activation state of a given subId.
2711 */
2712 @Override
2713 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002714 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002715
fionaxu0152e512016-11-14 13:36:14 -08002716 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002717 final long identity = Binder.clearCallingIdentity();
2718 try {
2719 if (phone != null) {
2720 return phone.getVoiceActivationState();
2721 } else {
2722 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2723 }
2724 } finally {
2725 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002726 }
2727 }
2728
2729 /**
2730 * Returns the data activation state of a given subId.
2731 */
2732 @Override
2733 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002734 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002735
fionaxu0152e512016-11-14 13:36:14 -08002736 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002737 final long identity = Binder.clearCallingIdentity();
2738 try {
2739 if (phone != null) {
2740 return phone.getDataActivationState();
2741 } else {
2742 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2743 }
2744 } finally {
2745 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002746 }
2747 }
2748
2749 /**
Wink Saville36469e72014-06-11 15:17:00 -07002750 * Returns the unread count of voicemails for a subId
2751 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002752 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002753 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2754 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2755 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2756 return 0;
2757 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002758 final long identity = Binder.clearCallingIdentity();
2759 try {
2760 final Phone phone = getPhone(subId);
2761 if (phone != null) {
2762 return phone.getVoiceMessageCount();
2763 } else {
2764 return 0;
2765 }
2766 } finally {
2767 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002768 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002769 }
2770
2771 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002772 * returns true, if the device is in a state where both voice and data
2773 * are supported simultaneously. This can change based on location or network condition.
2774 */
2775 @Override
2776 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002777 final long identity = Binder.clearCallingIdentity();
2778 try {
2779 final Phone phone = getPhone(subId);
2780 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2781 } finally {
2782 Binder.restoreCallingIdentity(identity);
2783 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002784 }
2785
2786 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002787 * Send the dialer code if called from the current default dialer or the caller has
2788 * carrier privilege.
2789 * @param inputCode The dialer code to send
2790 */
2791 @Override
2792 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002793 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002794 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002795 String defaultDialer = TelecomManager.from(defaultPhone.getContext())
2796 .getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002797 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002798 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2799 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002800 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002801
2802 final long identity = Binder.clearCallingIdentity();
2803 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002804 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002805 } finally {
2806 Binder.restoreCallingIdentity(identity);
2807 }
fionaxu235cc5e2017-03-06 22:25:57 -08002808 }
2809
2810 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002811 * Returns the data network type.
2812 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002813 *
2814 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2815 */
2816 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002817 public int getNetworkType() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002818 final long identity = Binder.clearCallingIdentity();
2819 try {
2820 final Phone phone = getPhone(getDefaultSubscription());
2821 if (phone != null) {
2822 return phone.getServiceState().getDataNetworkType();
2823 } else {
2824 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2825 }
2826 } finally {
2827 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002828 }
Wink Saville36469e72014-06-11 15:17:00 -07002829 }
2830
Pengquan Menga1bb6272018-09-06 09:59:22 -07002831 @Override
2832 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002833 if (!isActiveSubscription(subId)) {
2834 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2835 }
2836
Pengquan Menga1bb6272018-09-06 09:59:22 -07002837 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2838 }
2839
Brad Ebinger35c841c2018-10-01 10:40:55 -07002840 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002841 public boolean isInEmergencySmsMode() {
2842 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2843 final long identity = Binder.clearCallingIdentity();
2844 try {
2845 for (Phone phone : PhoneFactory.getPhones()) {
2846 if (phone.isInEmergencySmsMode()) {
2847 return true;
2848 }
2849 }
2850 } finally {
2851 Binder.restoreCallingIdentity(identity);
2852 }
2853 return false;
2854 }
2855
2856 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002857 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2858 throws RemoteException {
2859 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002860 final long token = Binder.clearCallingIdentity();
2861 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002862 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002863 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002864 .addRegistrationCallbackForSubscription(c, subId);
2865 } finally {
2866 Binder.restoreCallingIdentity(token);
2867 }
2868 }
2869
2870 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002871 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2872 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002873 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2874 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2875 }
2876 Binder.withCleanCallingIdentity(() -> {
2877 try {
2878 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002879 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002880 .removeRegistrationCallbackForSubscription(c, subId);
2881 } catch (IllegalArgumentException e) {
2882 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2883 + "is inactive, ignoring unregister.");
2884 // If the subscription is no longer active, just return, since the callback
2885 // will already have been removed internally.
2886 }
2887 });
Brad Ebinger35c841c2018-10-01 10:40:55 -07002888 }
2889
2890 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002891 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2892 throws RemoteException {
2893 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002894 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2895 final long token = Binder.clearCallingIdentity();
2896 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002897 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002898 .addCapabilitiesCallbackForSubscription(c, subId);
2899 } finally {
2900 Binder.restoreCallingIdentity(token);
2901 }
2902 }
2903
2904 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002905 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2906 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002907
2908 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2909 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2910 }
2911 Binder.withCleanCallingIdentity(() -> {
2912 try {
2913 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002914 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002915 .removeCapabilitiesCallbackForSubscription(c, subId);
2916 } catch (IllegalArgumentException e) {
2917 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
2918 + "is inactive, ignoring unregister.");
2919 // If the subscription is no longer active, just return, since the callback
2920 // will already have been removed internally.
2921 }
2922 });
Brad Ebinger35c841c2018-10-01 10:40:55 -07002923 }
2924
2925 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002926 public boolean isCapable(int subId, int capability, int regTech) {
2927 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002928 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2929 final long token = Binder.clearCallingIdentity();
2930 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002931 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002932 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2933 } catch (ImsException e) {
2934 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2935 return false;
Brad Ebinger6b5ac222019-02-04 14:36:52 -08002936 } catch (IllegalArgumentException e) {
2937 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
2938 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07002939 } finally {
2940 Binder.restoreCallingIdentity(token);
2941 }
2942 }
2943
2944 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002945 public boolean isAvailable(int subId, int capability, int regTech) {
2946 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002947 final long token = Binder.clearCallingIdentity();
2948 try {
2949 Phone phone = getPhone(subId);
2950 if (phone == null) return false;
2951 return phone.isImsCapabilityAvailable(capability, regTech);
2952 } finally {
2953 Binder.restoreCallingIdentity(token);
2954 }
2955 }
2956
2957 @Override
2958 public boolean isAdvancedCallingSettingEnabled(int subId) {
2959 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2960 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2961 final long token = Binder.clearCallingIdentity();
2962 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002963 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002964 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2965 } finally {
2966 Binder.restoreCallingIdentity(token);
2967 }
2968 }
2969
2970 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08002971 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002972 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08002973 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002974 final long identity = Binder.clearCallingIdentity();
2975 try {
2976 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002977 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002978 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2979 } finally {
2980 Binder.restoreCallingIdentity(identity);
2981 }
2982 }
2983
2984 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002985 public boolean isVtSettingEnabled(int subId) {
2986 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002987 final long identity = Binder.clearCallingIdentity();
2988 try {
2989 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002990 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002991 getSlotIndexOrException(subId)).isVtEnabledByUser();
2992 } finally {
2993 Binder.restoreCallingIdentity(identity);
2994 }
2995 }
2996
2997 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08002998 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002999 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003000 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003001 final long identity = Binder.clearCallingIdentity();
3002 try {
3003 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003004 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003005 } finally {
3006 Binder.restoreCallingIdentity(identity);
3007 }
3008 }
3009
3010 @Override
3011 public boolean isVoWiFiSettingEnabled(int subId) {
3012 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3013 final long identity = Binder.clearCallingIdentity();
3014 try {
3015 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003016 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003017 getSlotIndexOrException(subId)).isWfcEnabledByUser();
3018 } finally {
3019 Binder.restoreCallingIdentity(identity);
3020 }
3021 }
3022
3023 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003024 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003025 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003026 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003027 final long identity = Binder.clearCallingIdentity();
3028 try {
3029 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003030 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003031 } finally {
3032 Binder.restoreCallingIdentity(identity);
3033 }
3034 }
3035
3036 @Override
3037 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3038 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3039 final long identity = Binder.clearCallingIdentity();
3040 try {
3041 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003042 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003043 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
3044 } finally {
3045 Binder.restoreCallingIdentity(identity);
3046 }
3047 }
3048
3049 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003050 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003051 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003052 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003053 final long identity = Binder.clearCallingIdentity();
3054 try {
3055 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003056 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003057 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
3058 } finally {
3059 Binder.restoreCallingIdentity(identity);
3060 }
3061 }
3062
3063 @Override
3064 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3065 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3066 "setVoWiFiNonPersistent");
3067 final long identity = Binder.clearCallingIdentity();
3068 try {
3069 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003070 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003071 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003072 } finally {
3073 Binder.restoreCallingIdentity(identity);
3074 }
3075 }
3076
3077 @Override
3078 public int getVoWiFiModeSetting(int subId) {
3079 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3080 final long identity = Binder.clearCallingIdentity();
3081 try {
3082 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003083 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003084 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
3085 } finally {
3086 Binder.restoreCallingIdentity(identity);
3087 }
3088 }
3089
3090 @Override
3091 public void setVoWiFiModeSetting(int subId, int mode) {
3092 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3093 "setVoWiFiModeSetting");
3094 final long identity = Binder.clearCallingIdentity();
3095 try {
3096 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003097 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003098 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
3099 } finally {
3100 Binder.restoreCallingIdentity(identity);
3101 }
3102 }
3103
3104 @Override
3105 public int getVoWiFiRoamingModeSetting(int subId) {
3106 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3107 final long identity = Binder.clearCallingIdentity();
3108 try {
3109 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003110 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003111 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
3112 } finally {
3113 Binder.restoreCallingIdentity(identity);
3114 }
3115 }
3116
3117 @Override
3118 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3119 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3120 "setVoWiFiRoamingModeSetting");
3121 final long identity = Binder.clearCallingIdentity();
3122 try {
3123 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003124 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003125 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
3126 } finally {
3127 Binder.restoreCallingIdentity(identity);
3128 }
3129 }
3130
3131 @Override
3132 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3133 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3134 "setRttCapabilityEnabled");
3135 final long identity = Binder.clearCallingIdentity();
3136 try {
3137 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003138 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003139 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3140 } finally {
3141 Binder.restoreCallingIdentity(identity);
3142 }
3143 }
3144
3145 @Override
3146 public boolean isTtyOverVolteEnabled(int subId) {
3147 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3148 final long identity = Binder.clearCallingIdentity();
3149 try {
3150 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003151 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003152 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
3153 } finally {
3154 Binder.restoreCallingIdentity(identity);
3155 }
3156 }
3157
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003158 @Override
3159 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3160 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3161 final long identity = Binder.clearCallingIdentity();
3162 try {
3163 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003164 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003165 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003166 } finally {
3167 Binder.restoreCallingIdentity(identity);
3168 }
3169 }
3170
3171 @Override
3172 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3173 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3174 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003175 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3176 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3177 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003178 try {
3179 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003180 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003181 .removeProvisioningCallbackForSubscription(callback, subId);
3182 } catch (IllegalArgumentException e) {
3183 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3184 + "is inactive, ignoring unregister.");
3185 // If the subscription is no longer active, just return, since the callback will already
3186 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003187 } finally {
3188 Binder.restoreCallingIdentity(identity);
3189 }
3190 }
3191
3192 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003193 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3194 boolean isProvisioned) {
3195 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3196 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3197 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3198 }
3199 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3200 "setProvisioningStatusForCapability");
3201 final long identity = Binder.clearCallingIdentity();
3202 try {
3203 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3204 Phone phone = getPhone(subId);
3205 if (phone == null) {
3206 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3207 + subId);
3208 return;
3209 }
3210 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3211 return;
3212 }
3213
3214 // this capability requires provisioning, route to the correct API.
3215 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3216 switch (capability) {
3217 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3218 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3219 ims.setVolteProvisioned(isProvisioned);
3220 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3221 ims.setWfcProvisioned(isProvisioned);
3222 }
3223 break;
3224 }
3225 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3226 // There is currently no difference in VT provisioning type.
3227 ims.setVtProvisioned(isProvisioned);
3228 break;
3229 }
3230 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3231 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3232 // change the capability of the feature instead if needed.
3233 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3234 == isProvisioned) {
3235 // No change in provisioning.
3236 return;
3237 }
3238 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3239 try {
3240 ims.changeMmTelCapability(capability, tech, isProvisioned);
3241 } catch (ImsException e) {
3242 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3243 + ", Exception" + e.getMessage());
3244 }
3245 break;
3246 }
3247 default: {
3248 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3249 + capability + "', which does not require provisioning.");
3250 }
3251 }
3252
3253 } finally {
3254 Binder.restoreCallingIdentity(identity);
3255 }
3256 }
3257
3258 @Override
3259 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3260 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3261 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3262 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3263 }
3264 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3265 final long identity = Binder.clearCallingIdentity();
3266 try {
3267 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3268 Phone phone = getPhone(subId);
3269 if (phone == null) {
3270 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3271 + subId);
3272 // We will fail with "true" as the provisioning status because this is the default
3273 // if we do not require provisioning.
3274 return true;
3275 }
3276
3277 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3278 return true;
3279 }
3280
3281 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3282 switch (capability) {
3283 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3284 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3285 return ims.isVolteProvisionedOnDevice();
3286 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3287 return ims.isWfcProvisionedOnDevice();
3288 }
3289 // This should never happen, since we are checking tech above to make sure it
3290 // is either LTE or IWLAN.
3291 throw new IllegalArgumentException("Invalid radio technology for voice "
3292 + "capability.");
3293 }
3294 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3295 // There is currently no difference in VT provisioning type.
3296 return ims.isVtProvisionedOnDevice();
3297 }
3298 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3299 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3300 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3301 }
3302 default: {
3303 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3304 + capability + "', which does not require provisioning.");
3305 }
3306 }
3307
3308 } finally {
3309 Binder.restoreCallingIdentity(identity);
3310 }
3311 }
3312
3313 @Override
3314 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3315 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3316 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3317 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3318 }
3319 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3320 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3321 return (provisionedBits & capability) > 0;
3322 }
3323
3324 @Override
3325 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3326 boolean isProvisioned) {
3327 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3328 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3329 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3330 }
3331 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3332 "setProvisioningStatusForCapability");
3333 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3334 // If the current provisioning status for capability already matches isProvisioned,
3335 // do nothing.
3336 if (((provisionedBits & capability) > 0) == isProvisioned) {
3337 return;
3338 }
3339 if (isProvisioned) {
3340 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3341 } else {
3342 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3343 }
3344 }
3345
3346 /**
3347 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3348 * technology. The bitfield should mirror the bitfield defined by
3349 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3350 */
3351 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3352 String key = getMmTelProvisioningKey(subId, tech);
3353 // Default is no capabilities are provisioned.
3354 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3355 }
3356
3357 /**
3358 * Sets the MmTel capability provisioning bitfield (defined by
3359 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3360 * technology specified.
3361 *
3362 * Note: This is a synchronous command and should not be called on UI thread.
3363 */
3364 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3365 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3366 String key = getMmTelProvisioningKey(subId, tech);
3367 editor.putInt(key, newField);
3368 editor.commit();
3369 }
3370
3371 private static String getMmTelProvisioningKey(int subId, int tech) {
3372 // resulting key is provision_ims_mmtel_{subId}_{tech}
3373 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3374 }
3375
3376 /**
3377 * Query CarrierConfig to see if the specified capability requires provisioning for the
3378 * carrier associated with the subscription id.
3379 */
3380 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3381 int capability) {
3382 CarrierConfigManager configManager = new CarrierConfigManager(context);
3383 PersistableBundle c = configManager.getConfigForSubId(subId);
3384 boolean requireUtProvisioning = c.getBoolean(
3385 // By default, this config is true (even if there is no SIM). We also check to make
3386 // sure the subscription needs provisioning here, so we do not need to check for
3387 // the no-SIM case, where we would normally shortcut this to false.
3388 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, true)
3389 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3390 false);
3391 boolean requireVoiceVtProvisioning = c.getBoolean(
3392 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3393
3394 // First check to make sure that the capability requires provisioning.
3395 switch (capability) {
3396 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3397 // intentional fallthrough
3398 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3399 if (requireVoiceVtProvisioning) {
3400 // Voice and Video requires provisioning
3401 return true;
3402 }
3403 break;
3404 }
3405 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3406 if (requireUtProvisioning) {
3407 // UT requires provisioning
3408 return true;
3409 }
3410 break;
3411 }
3412 }
3413 return false;
3414 }
3415
3416 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003417 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003418 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3419 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3420 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003421 enforceReadPrivilegedPermission("getImsProvisioningInt");
3422 final long identity = Binder.clearCallingIdentity();
3423 try {
3424 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003425 int slotId = getSlotIndex(subId);
3426 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3427 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3428 + subId + "' for key:" + key);
3429 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3430 }
3431 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003432 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003433 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3434 + subId + "' for key:" + key);
3435 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003436 } finally {
3437 Binder.restoreCallingIdentity(identity);
3438 }
3439 }
3440
3441 @Override
3442 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003443 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3444 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3445 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003446 enforceReadPrivilegedPermission("getImsProvisioningString");
3447 final long identity = Binder.clearCallingIdentity();
3448 try {
3449 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003450 int slotId = getSlotIndex(subId);
3451 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3452 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3453 + subId + "' for key:" + key);
3454 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3455 }
3456 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003457 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003458 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3459 + subId + "' for key:" + key);
3460 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003461 } finally {
3462 Binder.restoreCallingIdentity(identity);
3463 }
3464 }
3465
3466 @Override
3467 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003468 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3469 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3470 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003471 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3472 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003473 final long identity = Binder.clearCallingIdentity();
3474 try {
3475 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003476 int slotId = getSlotIndex(subId);
3477 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3478 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3479 + subId + "' for key:" + key);
3480 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3481 }
3482 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003483 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003484 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3485 + "' for key:" + key);
3486 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003487 } finally {
3488 Binder.restoreCallingIdentity(identity);
3489 }
3490 }
3491
3492 @Override
3493 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003494 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3495 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3496 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003497 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3498 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003499 final long identity = Binder.clearCallingIdentity();
3500 try {
3501 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003502 int slotId = getSlotIndex(subId);
3503 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3504 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3505 + subId + "' for key:" + key);
3506 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3507 }
3508 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003509 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003510 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3511 + "' for key:" + key);
3512 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003513 } finally {
3514 Binder.restoreCallingIdentity(identity);
3515 }
3516 }
3517
Brad Ebinger35c841c2018-10-01 10:40:55 -07003518 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
3519 int slotId = SubscriptionManager.getSlotIndex(subId);
3520 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003521 throw new IllegalArgumentException("Invalid Subscription Id, subId=" + subId);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003522 }
3523 return slotId;
3524 }
3525
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003526 private int getSlotIndex(int subId) {
3527 int slotId = SubscriptionManager.getSlotIndex(subId);
3528 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3529 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3530 }
3531 return slotId;
3532 }
3533
Wink Saville36469e72014-06-11 15:17:00 -07003534 /**
3535 * Returns the network type for a subId
3536 */
3537 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003538 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003539 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003540 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003541 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3542 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003543
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003544 final long identity = Binder.clearCallingIdentity();
3545 try {
3546 final Phone phone = getPhone(subId);
3547 if (phone != null) {
3548 return phone.getServiceState().getDataNetworkType();
3549 } else {
3550 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3551 }
3552 } finally {
3553 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003554 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003555 }
3556
3557 /**
3558 * Returns the data network type
3559 */
3560 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003561 public int getDataNetworkType(String callingPackage) {
3562 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003563 }
3564
3565 /**
3566 * Returns the data network type for a subId
3567 */
3568 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003569 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003570 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003571 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003572 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3573 }
3574
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003575 final long identity = Binder.clearCallingIdentity();
3576 try {
3577 final Phone phone = getPhone(subId);
3578 if (phone != null) {
3579 return phone.getServiceState().getDataNetworkType();
3580 } else {
3581 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3582 }
3583 } finally {
3584 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003585 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003586 }
3587
3588 /**
Wink Saville36469e72014-06-11 15:17:00 -07003589 * Returns the Voice network type for a subId
3590 */
3591 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003592 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003593 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003594 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003595 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3596 }
3597
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003598 final long identity = Binder.clearCallingIdentity();
3599 try {
3600 final Phone phone = getPhone(subId);
3601 if (phone != null) {
3602 return phone.getServiceState().getVoiceNetworkType();
3603 } else {
3604 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3605 }
3606 } finally {
3607 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003608 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003609 }
3610
3611 /**
3612 * @return true if a ICC card is present
3613 */
3614 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003615 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003616 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3617 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003618 }
3619
3620 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003621 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003622 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003623 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003624 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003625 final long identity = Binder.clearCallingIdentity();
3626 try {
3627 final Phone phone = PhoneFactory.getPhone(slotIndex);
3628 if (phone != null) {
3629 return phone.getIccCard().hasIccCard();
3630 } else {
3631 return false;
3632 }
3633 } finally {
3634 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003635 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003636 }
3637
3638 /**
3639 * Return if the current radio is LTE on CDMA. This
3640 * is a tri-state return value as for a period of time
3641 * the mode may be unknown.
3642 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003643 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003644 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003645 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003646 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003647 @Override
3648 public int getLteOnCdmaMode(String callingPackage) {
3649 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003650 }
3651
Sanket Padawe356d7632015-06-22 14:03:32 -07003652 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003653 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003654 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003655 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003656 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3657 }
3658
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003659 final long identity = Binder.clearCallingIdentity();
3660 try {
3661 final Phone phone = getPhone(subId);
3662 if (phone == null) {
3663 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3664 } else {
3665 return phone.getLteOnCdmaMode();
3666 }
3667 } finally {
3668 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003669 }
Wink Saville36469e72014-06-11 15:17:00 -07003670 }
3671
Wink Saville36469e72014-06-11 15:17:00 -07003672 /**
3673 * {@hide}
3674 * Returns Default subId, 0 in the case of single standby.
3675 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003676 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003677 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003678 }
3679
Shishir Agrawala9f32182016-04-12 12:00:16 -07003680 private int getSlotForDefaultSubscription() {
3681 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3682 }
3683
Wink Savilleb564aae2014-10-23 10:18:09 -07003684 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003685 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003686 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003687
Pengquan Menge92a50d2018-09-21 15:54:48 -07003688 private boolean isActiveSubscription(int subId) {
3689 return mSubscriptionController.isActiveSubId(subId);
3690 }
3691
Ihab Awadf2177b72013-11-25 13:33:23 -08003692 /**
3693 * @see android.telephony.TelephonyManager.WifiCallingChoices
3694 */
3695 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003696 final long identity = Binder.clearCallingIdentity();
3697 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003698 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003699 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3700 getWhenToMakeWifiCallsDefaultPreference());
3701 } finally {
3702 Binder.restoreCallingIdentity(identity);
3703 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003704 }
3705
3706 /**
3707 * @see android.telephony.TelephonyManager.WifiCallingChoices
3708 */
3709 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003710 final long identity = Binder.clearCallingIdentity();
3711 try {
3712 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003713 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003714 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3715 } finally {
3716 Binder.restoreCallingIdentity(identity);
3717 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003718 }
3719
Sailesh Nepald1e68152013-12-12 19:08:02 -08003720 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003721 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003722 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003723 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003724
Jordan Liu4c733742019-02-28 12:03:40 -08003725 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
3726 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
3727 if (phoneId == -1) {
3728 throw new IllegalArgumentException("Given slot index: " + slotIndex
3729 + " does not correspond to an active phone");
3730 }
3731 return PhoneFactory.getPhone(phoneId);
3732 }
3733
Shishir Agrawal566b7612013-10-28 14:41:00 -07003734 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003735 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3736 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003737 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3738 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003739 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08003740 if (DBG) {
3741 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3742 }
3743 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
3744 p2);
3745 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003746
Jordan Liu4c733742019-02-28 12:03:40 -08003747
3748 @Override
3749 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
3750 int slotIndex, String callingPackage, String aid, int p2) {
3751 enforceModifyPermission();
3752 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3753 if (DBG) {
3754 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
3755 }
3756 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3757 callingPackage, aid, p2);
3758 }
3759
3760 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
3761 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003762 final long identity = Binder.clearCallingIdentity();
3763 try {
3764 if (TextUtils.equals(ISDR_AID, aid)) {
3765 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003766 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3767 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003768 if (bestComponent == null
3769 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3770 loge("The calling package is not allowed to access ISD-R.");
3771 throw new SecurityException(
3772 "The calling package is not allowed to access ISD-R.");
3773 }
Derek Tan740e1672017-06-27 14:56:27 -07003774 }
Derek Tan740e1672017-06-27 14:56:27 -07003775
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003776 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08003777 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
3778 null /* workSource */);
3779 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003780 return response;
3781 } finally {
3782 Binder.restoreCallingIdentity(identity);
3783 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003784 }
3785
3786 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003787 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003788 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3789 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08003790 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3791 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
3792 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003793
Jordan Liu4c733742019-02-28 12:03:40 -08003794 @Override
3795 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
3796 enforceModifyPermission();
3797 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
3798 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3799 channel);
3800 }
3801
3802 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003803 final long identity = Binder.clearCallingIdentity();
3804 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003805 if (channel < 0) {
3806 return false;
3807 }
Jordan Liu4c733742019-02-28 12:03:40 -08003808 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
3809 null /* workSource */);
3810 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003811 return success;
3812 } finally {
3813 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003814 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003815 }
3816
3817 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003818 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003819 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003820 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3821 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08003822 if (DBG) {
3823 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3824 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3825 + p3 + " data=" + data);
3826 }
3827 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
3828 command, p1, p2, p3, data);
3829 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003830
Jordan Liu4c733742019-02-28 12:03:40 -08003831 @Override
3832 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
3833 int command, int p1, int p2, int p3, String data) {
3834 enforceModifyPermission();
3835 if (DBG) {
3836 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
3837 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3838 + p3 + " data=" + data);
3839 }
3840 return iccTransmitApduLogicalChannelWithPermission(
3841 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
3842 data);
3843 }
3844
3845 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
3846 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003847 final long identity = Binder.clearCallingIdentity();
3848 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003849 if (channel < 0) {
3850 return "";
3851 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003852
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003853 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08003854 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
3855 null /* workSource */);
3856 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003857
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003858 // Append the returned status code to the end of the response payload.
3859 String s = Integer.toHexString(
3860 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3861 if (response.payload != null) {
3862 s = IccUtils.bytesToHexString(response.payload) + s;
3863 }
3864 return s;
3865 } finally {
3866 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003867 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003868 }
Jake Hambye994d462014-02-03 13:10:13 -08003869
Evan Charltonc66da362014-05-16 14:06:40 -07003870 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003871 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3872 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003873 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3874 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003875 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08003876 if (DBG) {
3877 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3878 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3879 }
3880 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
3881 cla, command, p1, p2, p3, data);
3882 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003883
Jordan Liu4c733742019-02-28 12:03:40 -08003884 @Override
3885 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
3886 int command, int p1, int p2, int p3, String data) {
3887 enforceModifyPermission();
3888 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3889 if (DBG) {
3890 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
3891 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
3892 + " data=" + data);
3893 }
3894
3895 return iccTransmitApduBasicChannelWithPermission(
3896 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
3897 p2, p3, data);
3898 }
3899
3900 // open APDU basic channel assuming the caller has sufficient permissions
3901 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
3902 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003903 final long identity = Binder.clearCallingIdentity();
3904 try {
3905 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3906 && TextUtils.equals(ISDR_AID, data)) {
3907 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003908 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3909 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003910 if (bestComponent == null
3911 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3912 loge("The calling package is not allowed to select ISD-R.");
3913 throw new SecurityException(
3914 "The calling package is not allowed to select ISD-R.");
3915 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003916 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003917
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003918 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08003919 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
3920 null /* workSource */);
3921 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003922
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003923 // Append the returned status code to the end of the response payload.
3924 String s = Integer.toHexString(
3925 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3926 if (response.payload != null) {
3927 s = IccUtils.bytesToHexString(response.payload) + s;
3928 }
3929 return s;
3930 } finally {
3931 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003932 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003933 }
3934
3935 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003936 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003937 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003938 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3939 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003940
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003941 final long identity = Binder.clearCallingIdentity();
3942 try {
3943 if (DBG) {
3944 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3945 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3946 }
3947
3948 IccIoResult response =
3949 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3950 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3951 subId);
3952
3953 if (DBG) {
3954 log("Exchange SIM_IO [R]" + response);
3955 }
3956
3957 byte[] result = null;
3958 int length = 2;
3959 if (response.payload != null) {
3960 length = 2 + response.payload.length;
3961 result = new byte[length];
3962 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3963 } else {
3964 result = new byte[length];
3965 }
3966
3967 result[length - 1] = (byte) response.sw2;
3968 result[length - 2] = (byte) response.sw1;
3969 return result;
3970 } finally {
3971 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003972 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003973 }
3974
Nathan Haroldb3014052017-01-25 15:57:32 -08003975 /**
3976 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3977 * on a particular subscription
3978 */
sqianb6e41952018-03-12 14:54:01 -07003979 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3980 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3981 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3982 return null;
3983 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003984
3985 final long identity = Binder.clearCallingIdentity();
3986 try {
3987 if (appType != TelephonyManager.APPTYPE_USIM
3988 && appType != TelephonyManager.APPTYPE_SIM) {
3989 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3990 return null;
3991 }
3992 Object response = sendRequest(
3993 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3994 if (response instanceof String[]) {
3995 return (String[]) response;
3996 }
3997 // Response is an Exception of some kind,
3998 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003999 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004000 } finally {
4001 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004002 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004003 }
4004
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004005 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004006 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004007 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4008 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004009
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004010 final long identity = Binder.clearCallingIdentity();
4011 try {
4012 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4013 if (response.payload == null) {
4014 return "";
4015 }
Evan Charltonc66da362014-05-16 14:06:40 -07004016
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004017 // Append the returned status code to the end of the response payload.
4018 String s = Integer.toHexString(
4019 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4020 s = IccUtils.bytesToHexString(response.payload) + s;
4021 return s;
4022 } finally {
4023 Binder.restoreCallingIdentity(identity);
4024 }
Evan Charltonc66da362014-05-16 14:06:40 -07004025 }
4026
Jake Hambye994d462014-02-03 13:10:13 -08004027 /**
4028 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4029 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4030 *
4031 * @param itemID the ID of the item to read
4032 * @return the NV item as a String, or null on error.
4033 */
4034 @Override
4035 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004036 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004037 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4038 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004039
4040 final long identity = Binder.clearCallingIdentity();
4041 try {
4042 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004043 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004044 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4045 return value;
4046 } finally {
4047 Binder.restoreCallingIdentity(identity);
4048 }
Jake Hambye994d462014-02-03 13:10:13 -08004049 }
4050
4051 /**
4052 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4053 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4054 *
4055 * @param itemID the ID of the item to read
4056 * @param itemValue the value to write, as a String
4057 * @return true on success; false on any failure
4058 */
4059 @Override
4060 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004061 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004062 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4063 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004064
4065 final long identity = Binder.clearCallingIdentity();
4066 try {
4067 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4068 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004069 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004070 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4071 return success;
4072 } finally {
4073 Binder.restoreCallingIdentity(identity);
4074 }
Jake Hambye994d462014-02-03 13:10:13 -08004075 }
4076
4077 /**
4078 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4079 * Used for device configuration by some CDMA operators.
4080 *
4081 * @param preferredRoamingList byte array containing the new PRL
4082 * @return true on success; false on any failure
4083 */
4084 @Override
4085 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004086 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4087 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004088
4089 final long identity = Binder.clearCallingIdentity();
4090 try {
4091 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4092 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4093 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4094 return success;
4095 } finally {
4096 Binder.restoreCallingIdentity(identity);
4097 }
Jake Hambye994d462014-02-03 13:10:13 -08004098 }
4099
4100 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004101 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004102 * Used for device configuration by some CDMA operators.
4103 *
chen xu6dac5ab2018-10-26 17:39:23 -07004104 * @param slotIndex - device slot.
4105 *
Jake Hambye994d462014-02-03 13:10:13 -08004106 * @return true on success; false on any failure
4107 */
4108 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004109 public boolean resetModemConfig(int slotIndex) {
4110 Phone phone = PhoneFactory.getPhone(slotIndex);
4111 if (phone != null) {
4112 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4113 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004114
chen xu6dac5ab2018-10-26 17:39:23 -07004115 final long identity = Binder.clearCallingIdentity();
4116 try {
4117 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4118 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4119 return success;
4120 } finally {
4121 Binder.restoreCallingIdentity(identity);
4122 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004123 }
chen xu6dac5ab2018-10-26 17:39:23 -07004124 return false;
4125 }
4126
4127 /**
4128 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4129 *
4130 * @param slotIndex - device slot.
4131 *
4132 * @return true on success; false on any failure
4133 */
4134 @Override
4135 public boolean rebootModem(int slotIndex) {
4136 Phone phone = PhoneFactory.getPhone(slotIndex);
4137 if (phone != null) {
4138 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4139 mApp, phone.getSubId(), "rebootModem");
4140
4141 final long identity = Binder.clearCallingIdentity();
4142 try {
4143 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4144 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4145 return success;
4146 } finally {
4147 Binder.restoreCallingIdentity(identity);
4148 }
4149 }
4150 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004151 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004152
Svet Ganovb320e182015-04-16 12:30:10 -07004153 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004154 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004155 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004156 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004157 return new String[0];
4158 }
4159
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004160 final long identity = Binder.clearCallingIdentity();
4161 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004162 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004163 } finally {
4164 Binder.restoreCallingIdentity(identity);
4165 }
Wink Saville36469e72014-06-11 15:17:00 -07004166 }
4167
Brad Ebinger51f743a2017-01-23 13:50:20 -08004168 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004169 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4170 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004171 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004172 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004173 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004174
4175 final long identity = Binder.clearCallingIdentity();
4176 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004177 ImsResolver resolver = PhoneFactory.getImsResolver();
4178 if (resolver == null) {
4179 // may happen if the device does not support IMS.
4180 return;
4181 }
4182 resolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004183 } finally {
4184 Binder.restoreCallingIdentity(identity);
4185 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004186 }
4187
4188 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004189 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4190 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004191 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004192 public void disableIms(int slotId) {
4193 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004194
4195 final long identity = Binder.clearCallingIdentity();
4196 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004197 ImsResolver resolver = PhoneFactory.getImsResolver();
4198 if (resolver == null) {
4199 // may happen if the device does not support IMS.
4200 return;
4201 }
4202 resolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004203 } finally {
4204 Binder.restoreCallingIdentity(identity);
4205 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004206 }
4207
4208 /**
4209 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4210 * feature or {@link null} if the service is not available. If the feature is available, the
4211 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4212 */
4213 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004214 IImsServiceFeatureCallback callback) {
4215 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004216
4217 final long identity = Binder.clearCallingIdentity();
4218 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004219 ImsResolver resolver = PhoneFactory.getImsResolver();
4220 if (resolver == null) {
4221 // may happen if the device does not support IMS.
4222 return null;
4223 }
4224 return resolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004225 } finally {
4226 Binder.restoreCallingIdentity(identity);
4227 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004228 }
4229
4230 /**
4231 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4232 * feature during emergency calling or {@link null} if the service is not available. If the
4233 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4234 * listener for feature updates.
4235 */
4236 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4237 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004238
4239 final long identity = Binder.clearCallingIdentity();
4240 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004241 ImsResolver resolver = PhoneFactory.getImsResolver();
4242 if (resolver == null) {
4243 // may happen if the device does not support IMS.
4244 return null;
4245 }
4246 return resolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004247 } finally {
4248 Binder.restoreCallingIdentity(identity);
4249 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004250 }
4251
Brad Ebinger5f64b052017-12-14 14:26:15 -08004252 /**
4253 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004254 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004255 */
4256 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4257 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004258
4259 final long identity = Binder.clearCallingIdentity();
4260 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004261 ImsResolver resolver = PhoneFactory.getImsResolver();
4262 if (resolver == null) {
4263 // may happen if the device does not support IMS.
4264 return null;
4265 }
4266 return resolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004267 } finally {
4268 Binder.restoreCallingIdentity(identity);
4269 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004270 }
4271
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004272 /**
4273 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004274 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004275 */
4276 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4277 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004278
4279 final long identity = Binder.clearCallingIdentity();
4280 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004281 ImsResolver resolver = PhoneFactory.getImsResolver();
4282 if (resolver == null) {
4283 // may happen if the device does not support IMS.
4284 return null;
4285 }
4286 return resolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004287 } finally {
4288 Binder.restoreCallingIdentity(identity);
4289 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004290 }
4291
Brad Ebinger884c07b2018-02-15 16:17:40 -08004292 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004293 * Sets the ImsService Package Name that Telephony will bind to.
4294 *
4295 * @param slotId the slot ID that the ImsService should bind for.
4296 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4297 * ImsService is the device default ImsService.
4298 * @param packageName The package name of the application that contains the ImsService to bind
4299 * to.
4300 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4301 * @hide
4302 */
4303 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004304 int[] subIds = SubscriptionManager.getSubId(slotId);
4305 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4306 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4307 "setImsService");
4308
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004309 final long identity = Binder.clearCallingIdentity();
4310 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004311 ImsResolver resolver = PhoneFactory.getImsResolver();
4312 if (resolver == null) {
4313 // may happen if the device does not support IMS.
4314 return false;
4315 }
4316 return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService,
4317 packageName);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004318 } finally {
4319 Binder.restoreCallingIdentity(identity);
4320 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004321 }
4322
4323 /**
4324 * Return the ImsService configuration.
4325 *
4326 * @param slotId The slot that the ImsService is associated with.
4327 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4328 * the device default.
4329 * @return the package name of the ImsService configuration.
4330 */
4331 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004332 int[] subIds = SubscriptionManager.getSubId(slotId);
4333 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4334 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4335 "getImsService");
4336
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004337 final long identity = Binder.clearCallingIdentity();
4338 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004339 ImsResolver resolver = PhoneFactory.getImsResolver();
4340 if (resolver == null) {
4341 // may happen if the device does not support IMS.
4342 return "";
4343 }
4344 return resolver.getImsServiceConfiguration(slotId, isCarrierImsService);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004345 } finally {
4346 Binder.restoreCallingIdentity(identity);
4347 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004348 }
4349
Wink Saville36469e72014-06-11 15:17:00 -07004350 public void setImsRegistrationState(boolean registered) {
4351 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004352
4353 final long identity = Binder.clearCallingIdentity();
4354 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004355 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004356 } finally {
4357 Binder.restoreCallingIdentity(identity);
4358 }
Wink Saville36469e72014-06-11 15:17:00 -07004359 }
4360
4361 /**
Stuart Scott54788802015-03-30 13:18:01 -07004362 * Set the network selection mode to automatic.
4363 *
4364 */
4365 @Override
4366 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004367 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4368 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004369
Pengquan Menge92a50d2018-09-21 15:54:48 -07004370 if (!isActiveSubscription(subId)) {
4371 return;
4372 }
4373
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004374 final long identity = Binder.clearCallingIdentity();
4375 try {
4376 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4377 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4378 } finally {
4379 Binder.restoreCallingIdentity(identity);
4380 }
Stuart Scott54788802015-03-30 13:18:01 -07004381 }
4382
Pengquan Mengea84e042018-09-20 14:57:26 -07004383 /**
4384 * Ask the radio to connect to the input network and change selection mode to manual.
4385 *
4386 * @param subId the id of the subscription.
4387 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4388 * the operator to attach to.
4389 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4390 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4391 * normal network selection next time.
4392 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004393 */
4394 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004395 public boolean setNetworkSelectionModeManual(
4396 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004397 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4398 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004399
4400 if (!isActiveSubscription(subId)) {
4401 return false;
4402 }
4403
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004404 final long identity = Binder.clearCallingIdentity();
4405 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004406 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004407 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004408 if (DBG) {
4409 log("setNetworkSelectionModeManual: subId: " + subId
4410 + " operator: " + operatorInfo);
4411 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004412 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4413 } finally {
4414 Binder.restoreCallingIdentity(identity);
4415 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004416 }
4417
4418 /**
4419 * Scans for available networks.
4420 */
4421 @Override
Hall Liuf19c44f2018-11-27 14:38:17 -08004422 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004423 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4424 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004425 LocationAccessPolicy.LocationPermissionResult locationResult =
4426 LocationAccessPolicy.checkLocationPermission(mApp,
4427 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4428 .setCallingPackage(callingPackage)
4429 .setCallingPid(Binder.getCallingPid())
4430 .setCallingUid(Binder.getCallingUid())
4431 .setMethod("getCellNetworkScanResults")
4432 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4433 .build());
4434 switch (locationResult) {
4435 case DENIED_HARD:
4436 throw new SecurityException("Not allowed to access scan results -- location");
4437 case DENIED_SOFT:
4438 return null;
4439 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004440
Pengquan Menga1bb6272018-09-06 09:59:22 -07004441 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004442 try {
4443 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004444 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004445 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004446 } finally {
4447 Binder.restoreCallingIdentity(identity);
4448 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004449 }
4450
4451 /**
yinxub1bed742017-04-17 11:45:04 -07004452 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004453 *
yinxub1bed742017-04-17 11:45:04 -07004454 * @param subId id of the subscription
4455 * @param request contains the radio access networks with bands/channels to scan
4456 * @param messenger callback messenger for scan results or errors
4457 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004458 * @return the id of the requested scan which can be used to stop the scan.
4459 */
4460 @Override
4461 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Hall Liuf19c44f2018-11-27 14:38:17 -08004462 IBinder binder, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004463 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4464 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004465 LocationAccessPolicy.LocationPermissionResult locationResult =
4466 LocationAccessPolicy.checkLocationPermission(mApp,
4467 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4468 .setCallingPackage(callingPackage)
4469 .setCallingPid(Binder.getCallingPid())
4470 .setCallingUid(Binder.getCallingUid())
4471 .setMethod("requestNetworkScan")
4472 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4473 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004474 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
4475 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request);
4476 if (e != null) {
4477 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4478 throw e;
4479 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07004480 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004481 return TelephonyScanManager.INVALID_SCAN_ID;
4482 }
4483 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004484 }
Hall Liu912dfd32019-04-25 14:02:26 -07004485 int callingUid = Binder.getCallingUid();
4486 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07004487 final long identity = Binder.clearCallingIdentity();
4488 try {
4489 return mNetworkScanRequestTracker.startNetworkScan(
4490 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07004491 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07004492 } finally {
4493 Binder.restoreCallingIdentity(identity);
4494 }
yinxu504e1392017-04-12 16:03:22 -07004495 }
4496
Hall Liub2ac8ef2019-02-28 15:56:23 -08004497 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
4498 NetworkScanRequest request) {
4499 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4500 != PERMISSION_GRANTED) {
4501 return new SecurityException("permission.NETWORK_SCAN is needed for network scans"
4502 + " without location access.");
4503 }
4504
4505 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4506 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004507 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4508 return new SecurityException("Specific channels must not be"
4509 + " scanned without location access.");
4510 }
4511 }
4512 }
4513
Hall Liub2ac8ef2019-02-28 15:56:23 -08004514 return null;
4515 }
4516
yinxu504e1392017-04-12 16:03:22 -07004517 /**
4518 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004519 *
4520 * @param subId id of the subscription
4521 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004522 */
4523 @Override
4524 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004525 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4526 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004527
Hall Liu912dfd32019-04-25 14:02:26 -07004528 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004529 final long identity = Binder.clearCallingIdentity();
4530 try {
Hall Liu912dfd32019-04-25 14:02:26 -07004531 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004532 } finally {
4533 Binder.restoreCallingIdentity(identity);
4534 }
yinxu504e1392017-04-12 16:03:22 -07004535 }
4536
4537 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004538 * Get the calculated preferred network type.
4539 * Used for debugging incorrect network type.
4540 *
4541 * @return the preferred network type, defined in RILConstants.java.
4542 */
4543 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004544 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004545 final Phone defaultPhone = getDefaultPhone();
4546 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4547 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004548 return RILConstants.PREFERRED_NETWORK_MODE;
4549 }
4550
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004551 final long identity = Binder.clearCallingIdentity();
4552 try {
4553 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004554 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004555 } finally {
4556 Binder.restoreCallingIdentity(identity);
4557 }
Junda Liu84d15a22014-07-02 11:21:04 -07004558 }
4559
4560 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004561 * Get the preferred network type.
4562 * Used for device configuration by some CDMA operators.
4563 *
4564 * @return the preferred network type, defined in RILConstants.java.
4565 */
4566 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004567 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08004568 TelephonyPermissions
4569 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4570 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004571
4572 final long identity = Binder.clearCallingIdentity();
4573 try {
4574 if (DBG) log("getPreferredNetworkType");
4575 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4576 int networkType = (result != null ? result[0] : -1);
4577 if (DBG) log("getPreferredNetworkType: " + networkType);
4578 return networkType;
4579 } finally {
4580 Binder.restoreCallingIdentity(identity);
4581 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004582 }
4583
4584 /**
4585 * Set the preferred network type.
4586 * Used for device configuration by some CDMA operators.
4587 *
4588 * @param networkType the preferred network type, defined in RILConstants.java.
4589 * @return true on success; false on any failure.
4590 */
4591 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004592 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004593 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4594 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004595
4596 final long identity = Binder.clearCallingIdentity();
4597 try {
4598 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4599 Boolean success = (Boolean) sendRequest(
4600 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4601 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4602 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004603 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004604 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4605 }
4606 return success;
4607 } finally {
4608 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004609 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004610 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004611
4612 /**
Miaoa84611c2019-03-15 09:21:10 +08004613 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004614 *
Miaoa84611c2019-03-15 09:21:10 +08004615 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004616 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004617 * @hide
4618 */
4619 @Override
Miaoa84611c2019-03-15 09:21:10 +08004620 public boolean getTetherApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004621 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004622 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08004623 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004624 try {
Miaoa84611c2019-03-15 09:21:10 +08004625 if (phone != null) {
4626 return phone.hasMatchedTetherApnSetting();
4627 } else {
4628 return false;
4629 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004630 } finally {
4631 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004632 }
Junda Liu475951f2014-11-07 16:45:03 -08004633 }
4634
4635 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004636 * Set mobile data enabled
4637 * Used by the user through settings etc to turn on/off mobile data
4638 *
4639 * @param enable {@code true} turn turn data on, else {@code false}
4640 */
4641 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004642 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004643 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4644 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004645
4646 final long identity = Binder.clearCallingIdentity();
4647 try {
4648 int phoneId = mSubscriptionController.getPhoneId(subId);
4649 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4650 Phone phone = PhoneFactory.getPhone(phoneId);
4651 if (phone != null) {
4652 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08004653 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004654 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004655 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004656 }
4657 } finally {
4658 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004659 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004660 }
4661
4662 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004663 * Get the user enabled state of Mobile Data.
4664 *
4665 * TODO: remove and use isUserDataEnabled.
4666 * This can't be removed now because some vendor codes
4667 * calls through ITelephony directly while they should
4668 * use TelephonyManager.
4669 *
4670 * @return true on enabled
4671 */
4672 @Override
4673 public boolean getDataEnabled(int subId) {
4674 return isUserDataEnabled(subId);
4675 }
4676
4677 /**
4678 * Get whether mobile data is enabled per user setting.
4679 *
4680 * There are other factors deciding whether mobile data is actually enabled, but they are
4681 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004682 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004683 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004684 *
4685 * @return {@code true} if data is enabled else {@code false}
4686 */
4687 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004688 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004689 try {
4690 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4691 null);
4692 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004693 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4694 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004695 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004696
4697 final long identity = Binder.clearCallingIdentity();
4698 try {
4699 int phoneId = mSubscriptionController.getPhoneId(subId);
4700 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4701 Phone phone = PhoneFactory.getPhone(phoneId);
4702 if (phone != null) {
4703 boolean retVal = phone.isUserDataEnabled();
4704 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4705 return retVal;
4706 } else {
4707 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4708 return false;
4709 }
4710 } finally {
4711 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004712 }
4713 }
4714
4715 /**
4716 * Get whether mobile data is enabled.
4717 *
4718 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4719 * whether mobile data is actually enabled.
4720 *
4721 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4722 *
4723 * @return {@code true} if data is enabled else {@code false}
4724 */
4725 @Override
4726 public boolean isDataEnabled(int subId) {
4727 try {
4728 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4729 null);
4730 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004731 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4732 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004733 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004734
4735 final long identity = Binder.clearCallingIdentity();
4736 try {
4737 int phoneId = mSubscriptionController.getPhoneId(subId);
4738 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4739 Phone phone = PhoneFactory.getPhone(phoneId);
4740 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08004741 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004742 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4743 return retVal;
4744 } else {
4745 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4746 return false;
4747 }
4748 } finally {
4749 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004750 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004751 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004752
4753 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004754 public int getCarrierPrivilegeStatus(int subId) {
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 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004761 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004762 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004763 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4764 }
4765 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004766 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004767 }
Junda Liu29340342014-07-10 15:23:27 -07004768
4769 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004770 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4771 final Phone phone = getPhone(subId);
4772 if (phone == null) {
4773 loge("getCarrierPrivilegeStatus: Invalid subId");
4774 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4775 }
4776 UiccProfile profile =
4777 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4778 if (profile == null) {
4779 loge("getCarrierPrivilegeStatus: No UICC");
4780 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4781 }
4782 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4783 }
4784
4785 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07004786 public int checkCarrierPrivilegesForPackage(String pkgName) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004787 final Phone defaultPhone = getDefaultPhone();
Junda Liu317d70b2016-03-08 09:33:53 -08004788 if (TextUtils.isEmpty(pkgName))
4789 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004790 UiccCard card = UiccController.getInstance().getUiccCard(defaultPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004791 if (card == null) {
4792 loge("checkCarrierPrivilegesForPackage: No UICC");
4793 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4794 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004795 return card.getCarrierPrivilegeStatus(defaultPhone.getContext().getPackageManager(),
4796 pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004797 }
4798
4799 @Override
4800 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004801 if (TextUtils.isEmpty(pkgName))
4802 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004803 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4804 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4805 UiccCard card = UiccController.getInstance().getUiccCard(i);
4806 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004807 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004808 continue;
4809 }
4810
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004811 result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004812 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4813 break;
4814 }
4815 }
4816
4817 return result;
Junda Liu29340342014-07-10 15:23:27 -07004818 }
Derek Tan89e89d42014-07-08 17:00:10 -07004819
4820 @Override
Junda Liue64de782015-04-16 17:19:16 -07004821 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4822 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4823 loge("phoneId " + phoneId + " is not valid.");
4824 return null;
4825 }
4826 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004827 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004828 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004829 return null ;
4830 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004831 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004832 }
4833
Amith Yamasani6e118872016-02-19 12:53:51 -08004834 @Override
4835 public List<String> getPackagesWithCarrierPrivileges() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004836 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08004837 List<String> privilegedPackages = new ArrayList<>();
4838 List<PackageInfo> packages = null;
4839 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4840 UiccCard card = UiccController.getInstance().getUiccCard(i);
4841 if (card == null) {
4842 // No UICC in that slot.
4843 continue;
4844 }
4845 if (card.hasCarrierPrivilegeRules()) {
4846 if (packages == null) {
4847 // Only check packages in user 0 for now
4848 packages = pm.getInstalledPackagesAsUser(
4849 PackageManager.MATCH_DISABLED_COMPONENTS
4850 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4851 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
4852 }
4853 for (int p = packages.size() - 1; p >= 0; p--) {
4854 PackageInfo pkgInfo = packages.get(p);
4855 if (pkgInfo != null && pkgInfo.packageName != null
4856 && card.getCarrierPrivilegeStatus(pkgInfo)
4857 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4858 privilegedPackages.add(pkgInfo.packageName);
4859 }
4860 }
4861 }
4862 }
4863 return privilegedPackages;
4864 }
4865
Wink Savilleb564aae2014-10-23 10:18:09 -07004866 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004867 final Phone phone = getPhone(subId);
4868 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004869 if (card == null) {
4870 loge("getIccId: No UICC");
4871 return null;
4872 }
4873 String iccId = card.getIccId();
4874 if (TextUtils.isEmpty(iccId)) {
4875 loge("getIccId: ICC ID is null or empty.");
4876 return null;
4877 }
4878 return iccId;
4879 }
4880
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004881 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004882 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4883 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004884 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4885 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004886
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004887 final long identity = Binder.clearCallingIdentity();
4888 try {
4889 final String iccId = getIccId(subId);
4890 final Phone phone = getPhone(subId);
4891 if (phone == null) {
4892 return false;
4893 }
4894 final String subscriberId = phone.getSubscriberId();
4895
4896 if (DBG_MERGE) {
4897 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4898 + subscriberId + " to " + number);
4899 }
4900
4901 if (TextUtils.isEmpty(iccId)) {
4902 return false;
4903 }
4904
4905 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4906
4907 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4908 if (alphaTag == null) {
4909 editor.remove(alphaTagPrefKey);
4910 } else {
4911 editor.putString(alphaTagPrefKey, alphaTag);
4912 }
4913
4914 // Record both the line number and IMSI for this ICCID, since we need to
4915 // track all merged IMSIs based on line number
4916 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4917 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4918 if (number == null) {
4919 editor.remove(numberPrefKey);
4920 editor.remove(subscriberPrefKey);
4921 } else {
4922 editor.putString(numberPrefKey, number);
4923 editor.putString(subscriberPrefKey, subscriberId);
4924 }
4925
4926 editor.commit();
4927 return true;
4928 } finally {
4929 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004930 }
Derek Tan7226c842014-07-02 17:42:23 -07004931 }
4932
4933 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004934 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004935 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004936 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004937 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004938 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004939 return null;
4940 }
Derek Tan97ebb422014-09-05 16:55:38 -07004941
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004942 final long identity = Binder.clearCallingIdentity();
4943 try {
4944 String iccId = getIccId(subId);
4945 if (iccId != null) {
4946 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4947 if (DBG_MERGE) {
4948 log("getLine1NumberForDisplay returning "
4949 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4950 }
4951 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004952 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004953 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4954 return null;
4955 } finally {
4956 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004957 }
Derek Tan7226c842014-07-02 17:42:23 -07004958 }
4959
4960 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004961 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004962 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004963 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004964 return null;
4965 }
Derek Tan97ebb422014-09-05 16:55:38 -07004966
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004967 final long identity = Binder.clearCallingIdentity();
4968 try {
4969 String iccId = getIccId(subId);
4970 if (iccId != null) {
4971 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4972 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4973 }
4974 return null;
4975 } finally {
4976 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004977 }
Derek Tan7226c842014-07-02 17:42:23 -07004978 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004979
4980 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004981 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004982 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4983 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004984 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004985 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4986 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004987 return null;
4988 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004989
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004990 final long identity = Binder.clearCallingIdentity();
4991 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004992 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004993 final TelephonyManager tele = TelephonyManager.from(context);
4994 final SubscriptionManager sub = SubscriptionManager.from(context);
4995
4996 // Figure out what subscribers are currently active
4997 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
4998 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4999 // the process, where TelephonyManager was instantiated.
5000 // Otherwise AppOps check will fail.
5001
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005002 final int[] subIds = sub.getActiveSubscriptionIdList();
5003 for (int subId : subIds) {
5004 activeSubscriberIds.add(tele.getSubscriberId(subId));
5005 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005006
5007 // First pass, find a number override for an active subscriber
5008 String mergeNumber = null;
5009 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5010 for (String key : prefs.keySet()) {
5011 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5012 final String subscriberId = (String) prefs.get(key);
5013 if (activeSubscriberIds.contains(subscriberId)) {
5014 final String iccId = key.substring(
5015 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5016 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5017 mergeNumber = (String) prefs.get(numberKey);
5018 if (DBG_MERGE) {
5019 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5020 + " for active subscriber " + subscriberId);
5021 }
5022 if (!TextUtils.isEmpty(mergeNumber)) {
5023 break;
5024 }
5025 }
5026 }
5027 }
5028
5029 // Shortcut when no active merged subscribers
5030 if (TextUtils.isEmpty(mergeNumber)) {
5031 return null;
5032 }
5033
5034 // Second pass, find all subscribers under that line override
5035 final ArraySet<String> result = new ArraySet<>();
5036 for (String key : prefs.keySet()) {
5037 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5038 final String number = (String) prefs.get(key);
5039 if (mergeNumber.equals(number)) {
5040 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5041 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5042 final String subscriberId = (String) prefs.get(subscriberKey);
5043 if (!TextUtils.isEmpty(subscriberId)) {
5044 result.add(subscriberId);
5045 }
5046 }
5047 }
5048 }
5049
5050 final String[] resultArray = result.toArray(new String[result.size()]);
5051 Arrays.sort(resultArray);
5052 if (DBG_MERGE) {
5053 Slog.d(LOG_TAG,
5054 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5055 }
5056 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005057 } finally {
5058 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005059 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005060 }
5061
5062 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005063 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005064 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5065 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005066
5067 final long identity = Binder.clearCallingIdentity();
5068 try {
5069 final Phone phone = getPhone(subId);
5070 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5071 } finally {
5072 Binder.restoreCallingIdentity(identity);
5073 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005074 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005075
5076 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005077 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005078 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5079 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005080 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005081
5082 final long identity = Binder.clearCallingIdentity();
5083 try {
5084 final Phone phone = getPhone(subId);
5085 if (phone == null) {
5086 return false;
5087 }
5088 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5089 cdmaNonRoamingList);
5090 } finally {
5091 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005092 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005093 }
5094
5095 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005096 @Deprecated
5097 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5098 enforceModifyPermission();
5099
5100 int returnValue = 0;
5101 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005102 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005103 if(result.exception == null) {
5104 if (result.result != null) {
5105 byte[] responseData = (byte[])(result.result);
5106 if(responseData.length > oemResp.length) {
5107 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5108 responseData.length + "bytes. Buffer Size is " +
5109 oemResp.length + "bytes.");
5110 }
5111 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5112 returnValue = responseData.length;
5113 }
5114 } else {
5115 CommandException ex = (CommandException) result.exception;
5116 returnValue = ex.getCommandError().ordinal();
5117 if(returnValue > 0) returnValue *= -1;
5118 }
5119 } catch (RuntimeException e) {
5120 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5121 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5122 if(returnValue > 0) returnValue *= -1;
5123 }
5124
5125 return returnValue;
5126 }
5127
5128 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005129 public void setRadioCapability(RadioAccessFamily[] rafs) {
5130 try {
5131 ProxyController.getInstance().setRadioCapability(rafs);
5132 } catch (RuntimeException e) {
5133 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5134 }
5135 }
5136
5137 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005138 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005139 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005140 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005141 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005142 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005143 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005144 final long identity = Binder.clearCallingIdentity();
5145 try {
chen xub97461a2018-10-26 14:17:57 -07005146 TelephonyPermissions
5147 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5148 mApp, phone.getSubId(), "getRadioAccessFamily");
5149 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005150 } finally {
5151 Binder.restoreCallingIdentity(identity);
5152 }
chen xub97461a2018-10-26 14:17:57 -07005153 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005154 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005155
5156 @Override
5157 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005158 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005159 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005160
5161 final long identity = Binder.clearCallingIdentity();
5162 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005163 ImsManager.getInstance(defaultPhone.getContext(),
5164 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005165 } finally {
5166 Binder.restoreCallingIdentity(identity);
5167 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005168 }
5169
5170 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005171 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005172 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00005173 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005174 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005175 return false;
5176 }
Svet Ganovb320e182015-04-16 12:30:10 -07005177
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005178 final long identity = Binder.clearCallingIdentity();
5179 try {
5180 // Check the user preference and the system-level IMS setting. Even if the user has
5181 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5182 // In the long run, we may instead need to check if there exists a connection service
5183 // which can support video calling.
5184 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005185 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005186 return imsManager.isVtEnabledByPlatform()
5187 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5188 && imsManager.isVtEnabledByUser();
5189 } finally {
5190 Binder.restoreCallingIdentity(identity);
5191 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005192 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005193
Andrew Leea1239f22015-03-02 17:44:07 -08005194 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005195 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
5196 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5197 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5198 return false;
5199 }
5200
5201 final long identity = Binder.clearCallingIdentity();
5202 try {
5203 CarrierConfigManager configManager =
5204 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005205 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005206 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5207 } finally {
5208 Binder.restoreCallingIdentity(identity);
5209 }
Andrew Leea1239f22015-03-02 17:44:07 -08005210 }
5211
5212 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005213 public boolean isWorldPhone(int subId, String callingPackage) {
5214 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5215 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5216 return false;
5217 }
5218
5219 final long identity = Binder.clearCallingIdentity();
5220 try {
5221 CarrierConfigManager configManager =
5222 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005223 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005224 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5225 } finally {
5226 Binder.restoreCallingIdentity(identity);
5227 }
Andrew Leea1239f22015-03-02 17:44:07 -08005228 }
5229
Andrew Lee9431b832015-03-09 18:46:45 -07005230 @Override
5231 public boolean isTtyModeSupported() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005232 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005233 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005234 }
5235
5236 @Override
5237 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005238 final long identity = Binder.clearCallingIdentity();
5239 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005240 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005241 } finally {
5242 Binder.restoreCallingIdentity(identity);
5243 }
Andrew Lee9431b832015-03-09 18:46:45 -07005244 }
5245
Hall Liuf6668912018-10-31 17:05:23 -07005246 /**
5247 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5248 * support for the feature and device firmware support.
5249 *
5250 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5251 */
5252 @Override
5253 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005254 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005255 final Phone phone = getPhone(subscriptionId);
5256 if (phone == null) {
5257 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5258 return false;
5259 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005260 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005261 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005262 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5263 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005264 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005265 return isCarrierSupported && isDeviceSupported;
5266 } finally {
5267 Binder.restoreCallingIdentity(identity);
5268 }
Hall Liu98187582018-01-22 19:15:32 -08005269 }
5270
Hall Liuf6668912018-10-31 17:05:23 -07005271 /**
5272 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
5273 * both also support RTT.
5274 */
5275 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005276 final long identity = Binder.clearCallingIdentity();
5277 try {
Hall Liuf6668912018-10-31 17:05:23 -07005278 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005279 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005280 } finally {
5281 Binder.restoreCallingIdentity(identity);
5282 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005283 }
5284
Sanket Padawe7310cc72015-01-14 09:53:20 -08005285 /**
5286 * Returns the unique device ID of phone, for example, the IMEI for
5287 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5288 *
5289 * <p>Requires Permission:
5290 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5291 */
5292 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005293 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005294 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005295 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005296 return null;
5297 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005298 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005299 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
5300 callingPackage, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005301 return null;
5302 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005303
5304 final long identity = Binder.clearCallingIdentity();
5305 try {
5306 return phone.getDeviceId();
5307 } finally {
5308 Binder.restoreCallingIdentity(identity);
5309 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005310 }
5311
Ping Sunc67b7c22016-03-02 19:16:45 +08005312 /**
5313 * {@hide}
5314 * Returns the IMS Registration Status on a particular subid
5315 *
5316 * @param subId
5317 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005318 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005319 Phone phone = getPhone(subId);
5320 if (phone != null) {
5321 return phone.isImsRegistered();
5322 } else {
5323 return false;
5324 }
5325 }
5326
Santos Cordon7a1885b2015-02-03 11:15:19 -08005327 @Override
5328 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005329 final long identity = Binder.clearCallingIdentity();
5330 try {
5331 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5332 } finally {
5333 Binder.restoreCallingIdentity(identity);
5334 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005335 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005336
Tyler Gunnf70ed162019-04-03 15:28:53 -07005337 @Override
5338 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5339 final long identity = Binder.clearCallingIdentity();
5340 try {
5341 Phone phone = getPhone(subscriptionId);
5342 if (phone == null) {
5343 return null;
5344 }
5345 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5346 } finally {
5347 Binder.restoreCallingIdentity(identity);
5348 }
5349 }
5350
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005351 /**
5352 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005353 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005354 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005355 final long identity = Binder.clearCallingIdentity();
5356 try {
5357 Phone phone = getPhone(subId);
5358 if (phone != null) {
5359 return phone.isWifiCallingEnabled();
5360 } else {
5361 return false;
5362 }
5363 } finally {
5364 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005365 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005366 }
5367
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005368 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005369 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005370 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005371 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005372 final long identity = Binder.clearCallingIdentity();
5373 try {
5374 Phone phone = getPhone(subId);
5375 if (phone != null) {
5376 return phone.isVideoEnabled();
5377 } else {
5378 return false;
5379 }
5380 } finally {
5381 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005382 }
5383 }
5384
5385 /**
5386 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5387 * defined in {@link ImsRegistrationImplBase}.
5388 */
5389 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005390 final long identity = Binder.clearCallingIdentity();
5391 try {
5392 Phone phone = getPhone(subId);
5393 if (phone != null) {
5394 return phone.getImsRegistrationTech();
5395 } else {
5396 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5397 }
5398 } finally {
5399 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005400 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005401 }
5402
Stuart Scott8eef64f2015-04-08 15:13:54 -07005403 @Override
5404 public void factoryReset(int subId) {
5405 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005406 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5407 return;
5408 }
5409
Svet Ganovcc087f82015-05-12 20:35:54 -07005410 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005411
Svet Ganovcc087f82015-05-12 20:35:54 -07005412 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005413 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5414 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005415 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005416 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005417 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005418 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5419 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005420 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005421 // There has been issues when Sms raw table somehow stores orphan
5422 // fragments. They lead to garbled message when new fragments come
5423 // in and combined with those stale ones. In case this happens again,
5424 // user can reset all network settings which will clean up this table.
5425 cleanUpSmsRawTable(getDefaultPhone().getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07005426 } finally {
5427 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005428 }
5429 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005430
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005431 private void cleanUpSmsRawTable(Context context) {
5432 ContentResolver resolver = context.getContentResolver();
5433 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5434 resolver.delete(uri, null, null);
5435 }
5436
Narayan Kamath1c496c22015-04-16 14:40:19 +01005437 @Override
chen xu5d3637b2019-01-21 23:31:38 -08005438 public String getSimLocaleForSubscriber(int subId) {
5439 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5440 final Phone phone = getPhone(subId);
5441 if (phone == null) {
5442 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08005443 return null;
chen xu5d3637b2019-01-21 23:31:38 -08005444 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005445 final long identity = Binder.clearCallingIdentity();
5446 try {
chen xu5d3637b2019-01-21 23:31:38 -08005447 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5448 phone.getContext().getOpPackageName());
chen xu6291c472019-02-04 12:55:53 -08005449 if (info == null) {
5450 log("getSimLocaleForSubscriber, inactive subId: " + subId);
5451 return null;
5452 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005453 // Try and fetch the locale from the carrier properties or from the SIM language
5454 // preferences (EF-PL and EF-LI)...
5455 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005456 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08005457 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5458 if (localeFromDefaultSim != null) {
5459 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5460 if (DBG) log("Using locale from subId: " + subId + " locale: "
5461 + localeFromDefaultSim);
5462 return localeFromDefaultSim.toLanguageTag();
5463 } else {
5464 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005465 }
5466 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005467
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005468 // The SIM language preferences only store a language (e.g. fr = French), not an
5469 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5470 // the SIM and carrier preferences does not include a country we add the country
5471 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005472 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005473 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08005474 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005475 return mccLocale.toLanguageTag();
5476 }
5477
5478 if (DBG) log("No locale found - returning null");
5479 return null;
5480 } finally {
5481 Binder.restoreCallingIdentity(identity);
5482 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005483 }
5484
5485 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005486 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005487 }
5488
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005489 /**
5490 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5491 */
5492 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005493 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005494 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005495
Chenjie Yu1ba97252018-01-11 18:16:20 -08005496 private final ModemActivityInfo mLastModemActivityInfo =
5497 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
5498
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005499 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005500 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5501 * representing the state of the modem.
5502 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005503 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5504 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005505 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005506 */
5507 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005508 public void requestModemActivityInfo(ResultReceiver result) {
5509 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005510 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005511
5512 final long identity = Binder.clearCallingIdentity();
5513 try {
5514 ModemActivityInfo ret = null;
5515 synchronized (mLastModemActivityInfo) {
5516 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5517 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07005518 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07005519 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005520 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
5521 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005522 mergedTxTimeMs[i] = info.getTxTimeMillis()[i]
5523 + mLastModemActivityInfo.getTxTimeMillis()[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005524 }
5525 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005526 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
5527 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005528 mLastModemActivityInfo.setIdleTimeMillis(
5529 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
5530 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
5531 mLastModemActivityInfo.setRxTimeMillis(
5532 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
5533 mLastModemActivityInfo.setEnergyUsed(
5534 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005535 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005536 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
5537 mLastModemActivityInfo.getSleepTimeMillis(),
5538 mLastModemActivityInfo.getIdleTimeMillis(),
5539 mLastModemActivityInfo.getTxTimeMillis(),
5540 mLastModemActivityInfo.getRxTimeMillis(),
5541 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005542 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005543 Bundle bundle = new Bundle();
5544 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
5545 result.send(0, bundle);
5546 } finally {
5547 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005548 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005549 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005550
Siddharth Rayb8114062018-06-17 15:02:38 -07005551 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
5552 // less than total activity duration.
5553 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
5554 if (info == null) {
5555 return false;
5556 }
5557 int activityDurationMs =
5558 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
5559 int totalTxTimeMs = 0;
5560 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
5561 totalTxTimeMs += info.getTxTimeMillis()[i];
5562 }
5563 return (info.isValid()
5564 && (info.getSleepTimeMillis() <= activityDurationMs)
5565 && (info.getIdleTimeMillis() <= activityDurationMs)
5566 && (info.getRxTimeMillis() <= activityDurationMs)
5567 && (totalTxTimeMs <= activityDurationMs));
5568 }
5569
Jack Yu85bd38a2015-11-09 11:34:32 -08005570 /**
5571 * {@hide}
5572 * Returns the service state information on specified subscription.
5573 */
5574 @Override
5575 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005576 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005577 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08005578 return null;
5579 }
5580
Hall Liuf19c44f2018-11-27 14:38:17 -08005581 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
5582 LocationAccessPolicy.checkLocationPermission(mApp,
5583 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5584 .setCallingPackage(callingPackage)
5585 .setCallingPid(Binder.getCallingPid())
5586 .setCallingUid(Binder.getCallingUid())
5587 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07005588 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005589 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5590 .build());
5591
5592 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
5593 LocationAccessPolicy.checkLocationPermission(mApp,
5594 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5595 .setCallingPackage(callingPackage)
5596 .setCallingPid(Binder.getCallingPid())
5597 .setCallingUid(Binder.getCallingUid())
5598 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07005599 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005600 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5601 .build());
5602 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
5603 boolean hasFinePermission =
5604 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5605 boolean hasCoarsePermission =
5606 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5607
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005608 final long identity = Binder.clearCallingIdentity();
5609 try {
5610 final Phone phone = getPhone(subId);
5611 if (phone == null) {
5612 return null;
5613 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005614
Hall Liuf19c44f2018-11-27 14:38:17 -08005615 ServiceState ss = phone.getServiceState();
5616
5617 // Scrub out the location info in ServiceState depending on what level of access
5618 // the caller has.
5619 if (hasFinePermission) return ss;
5620 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
5621 return ss.sanitizeLocationInfo(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005622 } finally {
5623 Binder.restoreCallingIdentity(identity);
5624 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005625 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005626
5627 /**
5628 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
5629 *
5630 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5631 * voicemail ringtone.
5632 * @return The URI for the ringtone to play when receiving a voicemail from a specific
5633 * PhoneAccount.
5634 */
5635 @Override
5636 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005637 final long identity = Binder.clearCallingIdentity();
5638 try {
5639 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5640 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005641 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005642 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005643
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005644 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
5645 } finally {
5646 Binder.restoreCallingIdentity(identity);
5647 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005648 }
5649
5650 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005651 * Sets the per-account voicemail ringtone.
5652 *
5653 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5654 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5655 *
5656 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5657 * voicemail ringtone.
5658 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5659 * PhoneAccount.
5660 */
5661 @Override
5662 public void setVoicemailRingtoneUri(String callingPackage,
5663 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005664 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005665 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5666 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005667 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005668 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5669 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5670 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005671 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005672
5673 final long identity = Binder.clearCallingIdentity();
5674 try {
5675 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5676 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005677 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005678 }
5679 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5680 } finally {
5681 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005682 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005683 }
5684
5685 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005686 * Returns whether vibration is set for voicemail notification in Phone settings.
5687 *
5688 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5689 * voicemail vibration setting.
5690 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5691 */
5692 @Override
5693 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005694 final long identity = Binder.clearCallingIdentity();
5695 try {
5696 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5697 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005698 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005699 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005700
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005701 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5702 } finally {
5703 Binder.restoreCallingIdentity(identity);
5704 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005705 }
5706
Youhan Wange64578a2016-05-02 15:32:42 -07005707 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005708 * Sets the per-account voicemail vibration.
5709 *
5710 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5711 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5712 *
5713 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5714 * voicemail vibration setting.
5715 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5716 * specific PhoneAccount.
5717 */
5718 @Override
5719 public void setVoicemailVibrationEnabled(String callingPackage,
5720 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005721 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005722 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5723 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005724 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005725 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5726 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5727 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005728 }
5729
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005730 final long identity = Binder.clearCallingIdentity();
5731 try {
5732 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5733 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005734 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005735 }
5736 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5737 } finally {
5738 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005739 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005740 }
5741
5742 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005743 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5744 *
5745 * @throws SecurityException if the caller does not have the required permission
5746 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005747 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005748 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07005749 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005750 }
5751
5752 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005753 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5754 * permission.
5755 *
5756 * @throws SecurityException if the caller does not have the required permission
5757 */
5758 private void enforceSendSmsPermission() {
5759 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5760 }
5761
5762 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005763 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005764 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005765 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005766 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005767 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005768 final long identity = Binder.clearCallingIdentity();
5769 try {
5770 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005771 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005772 if (componentName == null) {
5773 throw new SecurityException(
5774 "Caller not current active visual voicemail package[null]");
5775 }
5776 String vvmPackage = componentName.getPackageName();
5777 if (!callingPackage.equals(vvmPackage)) {
5778 throw new SecurityException("Caller not current active visual voicemail package["
5779 + vvmPackage + "]");
5780 }
5781 } finally {
5782 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005783 }
5784 }
5785
5786 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005787 * Return the application ID for the app type.
5788 *
5789 * @param subId the subscription ID that this request applies to.
5790 * @param appType the uicc app type.
5791 * @return Application ID for specificied app type, or null if no uicc.
5792 */
5793 @Override
5794 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005795 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005796 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005797
5798 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005799 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005800 if (phone == null) {
5801 return null;
5802 }
5803 String aid = null;
5804 try {
5805 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5806 .getApplicationByType(appType).getAid();
5807 } catch (Exception e) {
5808 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5809 }
5810 return aid;
5811 } finally {
5812 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005813 }
Youhan Wange64578a2016-05-02 15:32:42 -07005814 }
5815
Youhan Wang4001d252016-05-11 10:29:41 -07005816 /**
5817 * Return the Electronic Serial Number.
5818 *
5819 * @param subId the subscription ID that this request applies to.
5820 * @return ESN or null if error.
5821 */
5822 @Override
5823 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005824 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005825 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005826
5827 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005828 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005829 if (phone == null) {
5830 return null;
5831 }
5832 String esn = null;
5833 try {
5834 esn = phone.getEsn();
5835 } catch (Exception e) {
5836 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5837 }
5838 return esn;
5839 } finally {
5840 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005841 }
Youhan Wang4001d252016-05-11 10:29:41 -07005842 }
5843
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005844 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005845 * Return the Preferred Roaming List Version.
5846 *
5847 * @param subId the subscription ID that this request applies to.
5848 * @return PRLVersion or null if error.
5849 */
5850 @Override
5851 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005852 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005853 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005854
5855 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005856 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005857 if (phone == null) {
5858 return null;
5859 }
5860 String cdmaPrlVersion = null;
5861 try {
5862 cdmaPrlVersion = phone.getCdmaPrlVersion();
5863 } catch (Exception e) {
5864 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5865 }
5866 return cdmaPrlVersion;
5867 } finally {
5868 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005869 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005870 }
5871
5872 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005873 * Get snapshot of Telephony histograms
5874 * @return List of Telephony histograms
5875 * @hide
5876 */
5877 @Override
5878 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005879 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5880 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005881
5882 final long identity = Binder.clearCallingIdentity();
5883 try {
5884 return RIL.getTelephonyRILTimingHistograms();
5885 } finally {
5886 Binder.restoreCallingIdentity(identity);
5887 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005888 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005889
5890 /**
5891 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08005892 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
5893 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005894 * Require system privileges. In the future we may add this to carrier APIs.
5895 *
Michele Berionne482f8202018-11-27 18:57:59 -08005896 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005897 */
5898 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08005899 @TelephonyManager.SetCarrierRestrictionResult
5900 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005901 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005902 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005903
Michele Berionne482f8202018-11-27 18:57:59 -08005904 if (carrierRestrictionRules == null) {
5905 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08005906 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005907
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005908 final long identity = Binder.clearCallingIdentity();
5909 try {
Michele Berionne482f8202018-11-27 18:57:59 -08005910 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07005911 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005912 } finally {
5913 Binder.restoreCallingIdentity(identity);
5914 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005915 }
5916
5917 /**
5918 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08005919 * Get the allowed carrier list and the excluded carrier list, including the priority between
5920 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005921 * Require system privileges. In the future we may add this to carrier APIs.
5922 *
Michele Berionne482f8202018-11-27 18:57:59 -08005923 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07005924 */
5925 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08005926 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005927 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07005928 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005929
5930 final long identity = Binder.clearCallingIdentity();
5931 try {
Michele Berionne482f8202018-11-27 18:57:59 -08005932 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
5933 if (response instanceof CarrierRestrictionRules) {
5934 return (CarrierRestrictionRules) response;
5935 }
5936 // Response is an Exception of some kind,
5937 // which is signalled to the user as a NULL retval
5938 return null;
5939 } catch (Exception e) {
5940 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
5941 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005942 } finally {
5943 Binder.restoreCallingIdentity(identity);
5944 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005945 }
5946
fionaxu59545b42016-05-25 15:53:37 -07005947 /**
5948 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5949 * @param subId the subscription ID that this action applies to.
5950 * @param enabled control enable or disable metered apns.
5951 * {@hide}
5952 */
5953 @Override
5954 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5955 enforceModifyPermission();
5956 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005957
5958 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005959 if (phone == null) {
5960 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5961 return;
5962 }
5963 try {
5964 phone.carrierActionSetMeteredApnsEnabled(enabled);
5965 } catch (Exception e) {
5966 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005967 } finally {
5968 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005969 }
5970 }
5971
5972 /**
5973 * Action set from carrier signalling broadcast receivers to enable/disable radio
5974 * @param subId the subscription ID that this action applies to.
5975 * @param enabled control enable or disable radio.
5976 * {@hide}
5977 */
5978 @Override
5979 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5980 enforceModifyPermission();
5981 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005982
5983 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005984 if (phone == null) {
5985 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5986 return;
5987 }
5988 try {
5989 phone.carrierActionSetRadioEnabled(enabled);
5990 } catch (Exception e) {
5991 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005992 } finally {
5993 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005994 }
5995 }
5996
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005997 /**
fionaxu8da9cb12017-05-23 15:02:46 -07005998 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
5999 * network status based on which carrier apps could apply actions accordingly,
6000 * enable/disable default url handler for example.
6001 *
6002 * @param subId the subscription ID that this action applies to.
6003 * @param report control start/stop reporting the default network status.
6004 * {@hide}
6005 */
6006 @Override
6007 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6008 enforceModifyPermission();
6009 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006010
6011 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006012 if (phone == null) {
6013 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6014 return;
6015 }
6016 try {
6017 phone.carrierActionReportDefaultNetworkStatus(report);
6018 } catch (Exception e) {
6019 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006020 } finally {
6021 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006022 }
6023 }
6024
6025 /**
fionaxud9622282017-07-17 17:51:30 -07006026 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6027 * @param subId the subscription ID that this action applies to.
6028 * {@hide}
6029 */
6030 @Override
6031 public void carrierActionResetAll(int subId) {
6032 enforceModifyPermission();
6033 final Phone phone = getPhone(subId);
6034 if (phone == null) {
6035 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6036 return;
6037 }
6038 try {
6039 phone.carrierActionResetAll();
6040 } catch (Exception e) {
6041 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6042 }
6043 }
6044
6045 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006046 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6047 * bug report is being generated.
6048 */
6049 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006050 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006051 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6052 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006053 writer.println("Permission Denial: can't dump Phone from pid="
6054 + Binder.getCallingPid()
6055 + ", uid=" + Binder.getCallingUid()
6056 + "without permission "
6057 + android.Manifest.permission.DUMP);
6058 return;
6059 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006060 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006061 }
Jack Yueb89b242016-06-22 13:27:47 -07006062
Brad Ebingerdac2f002018-04-03 15:17:52 -07006063 @Override
6064 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6065 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6066 throws RemoteException {
6067 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
6068 }
6069
Jack Yueb89b242016-06-22 13:27:47 -07006070 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006071 * Get aggregated video call data usage since boot.
6072 *
6073 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6074 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006075 * {@hide}
6076 */
6077 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006078 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006079 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6080 null);
6081
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006082 final long identity = Binder.clearCallingIdentity();
6083 try {
6084 // NetworkStatsService keeps tracking the active network interface and identity. It
6085 // records the delta with the corresponding network identity.
6086 // We just return the total video call data usage snapshot since boot.
6087 Phone phone = getPhone(subId);
6088 if (phone != null) {
6089 return phone.getVtDataUsage(perUidStats);
6090 }
6091 return null;
6092 } finally {
6093 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006094 }
Jack Yueb89b242016-06-22 13:27:47 -07006095 }
Jack Yu75ab2952016-07-08 14:29:33 -07006096
6097 /**
6098 * Policy control of data connection. Usually used when data limit is passed.
6099 * @param enabled True if enabling the data, otherwise disabling.
6100 * @param subId Subscription index
6101 * {@hide}
6102 */
6103 @Override
6104 public void setPolicyDataEnabled(boolean enabled, int subId) {
6105 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006106
6107 final long identity = Binder.clearCallingIdentity();
6108 try {
6109 Phone phone = getPhone(subId);
6110 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006111 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006112 }
6113 } finally {
6114 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006115 }
6116 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006117
6118 /**
6119 * Get Client request stats
6120 * @return List of Client Request Stats
6121 * @hide
6122 */
6123 @Override
6124 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006125 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006126 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006127 return null;
6128 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006129 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006130
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006131 final long identity = Binder.clearCallingIdentity();
6132 try {
6133 if (phone != null) {
6134 return phone.getClientRequestStats();
6135 }
6136
6137 return null;
6138 } finally {
6139 Binder.restoreCallingIdentity(identity);
6140 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006141 }
6142
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006143 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006144 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006145 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006146 }
Jack Yueb4124c2017-02-16 15:32:43 -08006147
6148 /**
Grace Chen70990072017-03-24 17:21:30 -07006149 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006150 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006151 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006152 * @param state State of SIM (power down, power up, pass through)
6153 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6154 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6155 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006156 *
6157 **/
6158 @Override
Grace Chen70990072017-03-24 17:21:30 -07006159 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006160 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006161 Phone phone = PhoneFactory.getPhone(slotIndex);
6162
vagdeviaf9a5b92018-08-15 16:01:53 -07006163 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6164
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006165 final long identity = Binder.clearCallingIdentity();
6166 try {
6167 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006168 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006169 }
6170 } finally {
6171 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006172 }
6173 }
Shuo Qiandd210312017-04-12 22:11:33 +00006174
Tyler Gunn65d45c22017-06-05 11:22:26 -07006175 private boolean isUssdApiAllowed(int subId) {
6176 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006177 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006178 if (configManager == null) {
6179 return false;
6180 }
6181 PersistableBundle pb = configManager.getConfigForSubId(subId);
6182 if (pb == null) {
6183 return false;
6184 }
6185 return pb.getBoolean(
6186 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6187 }
6188
Shuo Qiandd210312017-04-12 22:11:33 +00006189 /**
6190 * Check if phone is in emergency callback mode
6191 * @return true if phone is in emergency callback mode
6192 * @param subId sub id
6193 */
goneil9c5f4872017-12-05 14:07:56 -08006194 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006195 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006196 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006197 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006198
6199 final long identity = Binder.clearCallingIdentity();
6200 try {
6201 if (phone != null) {
6202 return phone.isInEcm();
6203 } else {
6204 return false;
6205 }
6206 } finally {
6207 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006208 }
6209 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006210
6211 /**
6212 * Get the current signal strength information for the given subscription.
6213 * Because this information is not updated when the device is in a low power state
6214 * it should not be relied-upon to be current.
6215 * @param subId Subscription index
6216 * @return the most recent cached signal strength info from the modem
6217 */
6218 @Override
6219 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006220 final long identity = Binder.clearCallingIdentity();
6221 try {
6222 Phone p = getPhone(subId);
6223 if (p == null) {
6224 return null;
6225 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006226
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006227 return p.getSignalStrength();
6228 } finally {
6229 Binder.restoreCallingIdentity(identity);
6230 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006231 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006232
Pengquan Meng77b7f132018-08-22 14:49:57 -07006233 /**
Chen Xuf792fd62018-10-17 17:54:36 +00006234 * Get the current modem radio state for the given slot.
6235 * @param slotIndex slot index.
6236 * @param callingPackage the name of the package making the call.
6237 * @return the current radio power state from the modem
6238 */
6239 @Override
6240 public int getRadioPowerState(int slotIndex, String callingPackage) {
6241 Phone phone = PhoneFactory.getPhone(slotIndex);
6242 if (phone != null) {
6243 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6244 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
6245 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6246 }
6247
6248 final long identity = Binder.clearCallingIdentity();
6249 try {
6250 return phone.getRadioPowerState();
6251 } finally {
6252 Binder.restoreCallingIdentity(identity);
6253 }
6254 }
6255 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6256 }
6257
6258 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07006259 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6260 *
6261 * <p>Requires one of the following permissions:
6262 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6263 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6264 * privileges.
6265 *
6266 * @param subId subscription id
6267 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6268 * {@code false}.
6269 */
6270 @Override
6271 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006272 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6273 null /* message */);
6274
Pengquan Menga1bb6272018-09-06 09:59:22 -07006275 boolean isEnabled = false;
6276 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07006277 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006278 Phone phone = getPhone(subId);
6279 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006280 } catch (Exception e) {
6281 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6282 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07006283 } finally {
6284 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006285 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006286 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006287 }
6288
6289
6290 /**
6291 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6292 *
6293 * <p> Requires permission:
6294 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6295 * privileges.
6296 *
6297 * @param subId subscription id
6298 * @param isEnabled {@code true} means enable, {@code false} means disable.
6299 */
6300 @Override
6301 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006302 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6303 mApp, subId, "setDataRoamingEnabled");
6304
Pengquan Menga1bb6272018-09-06 09:59:22 -07006305 final long identity = Binder.clearCallingIdentity();
6306 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006307 Phone phone = getPhone(subId);
6308 if (phone != null) {
6309 phone.setDataRoamingEnabled(isEnabled);
6310 }
6311 } finally {
6312 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006313 }
6314 }
6315
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006316 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006317 public boolean isManualNetworkSelectionAllowed(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006318 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6319 mApp, subId, "isManualNetworkSelectionAllowed");
6320
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006321 boolean isAllowed = true;
6322 final long identity = Binder.clearCallingIdentity();
6323 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006324 Phone phone = getPhone(subId);
6325 if (phone != null) {
6326 isAllowed = phone.isCspPlmnEnabled();
6327 }
6328 } finally {
6329 Binder.restoreCallingIdentity(identity);
6330 }
6331 return isAllowed;
6332 }
6333
6334 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006335 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006336 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08006337 try {
6338 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07006339 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08006340 } catch (SecurityException e) {
6341 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6342 // has carrier privileges on an active UICC
6343 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6344 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006345 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08006346 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006347 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006348
6349 final long identity = Binder.clearCallingIdentity();
6350 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006351 UiccController uiccController = UiccController.getInstance();
6352 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07006353 if (hasReadPermission) {
6354 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006355 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07006356
6357 // Remove private info if the caller doesn't have access
6358 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6359 for (UiccCardInfo cardInfo : cardInfos) {
6360 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6361 // is available
6362 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
6363 if (card == null || card.getUiccProfile() == null) {
6364 // assume no access if the card or profile is unavailable
6365 filteredInfos.add(cardInfo.getUnprivileged());
6366 continue;
6367 }
6368 UiccProfile profile = card.getUiccProfile();
6369 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6370 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6371 filteredInfos.add(cardInfo);
6372 } else {
6373 filteredInfos.add(cardInfo.getUnprivileged());
6374 }
6375 }
6376 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08006377 } finally {
6378 Binder.restoreCallingIdentity(identity);
6379 }
6380 }
6381
6382 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006383 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006384 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006385
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006386 final long identity = Binder.clearCallingIdentity();
6387 try {
6388 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6389 if (slots == null) {
6390 Rlog.i(LOG_TAG, "slots is null.");
6391 return null;
6392 }
6393
6394 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6395 for (int i = 0; i < slots.length; i++) {
6396 UiccSlot slot = slots[i];
6397 if (slot == null) {
6398 continue;
6399 }
6400
Jordan Liu7be7e652019-05-06 18:55:02 +00006401 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006402 UiccCard card = slot.getUiccCard();
6403 if (card != null) {
6404 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00006405 } else {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006406 cardId = slot.getIccId();
6407 }
6408
6409 int cardState = 0;
6410 switch (slot.getCardState()) {
6411 case CARDSTATE_ABSENT:
6412 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6413 break;
6414 case CARDSTATE_PRESENT:
6415 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6416 break;
6417 case CARDSTATE_ERROR:
6418 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6419 break;
6420 case CARDSTATE_RESTRICTED:
6421 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6422 break;
6423 default:
6424 break;
6425
6426 }
6427
6428 infos[i] = new UiccSlotInfo(
6429 slot.isActive(),
6430 slot.isEuicc(),
6431 cardId,
6432 cardState,
6433 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08006434 slot.isExtendedApduSupported(),
6435 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006436 }
6437 return infos;
6438 } finally {
6439 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006440 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006441 }
6442
6443 @Override
6444 public boolean switchSlots(int[] physicalSlots) {
6445 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006446
6447 final long identity = Binder.clearCallingIdentity();
6448 try {
6449 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6450 } finally {
6451 Binder.restoreCallingIdentity(identity);
6452 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006453 }
Jack Yu4c988042018-02-27 15:30:01 -08006454
6455 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006456 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006457 final long identity = Binder.clearCallingIdentity();
6458 try {
6459 return UiccController.getInstance().getCardIdForDefaultEuicc();
6460 } finally {
6461 Binder.restoreCallingIdentity(identity);
6462 }
6463 }
6464
6465 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006466 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6467 enforceModifyPermission();
6468 final Phone phone = getPhone(subId);
6469 if (phone == null) {
6470 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6471 return;
6472 }
6473
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006474 final long identity = Binder.clearCallingIdentity();
6475 try {
6476 phone.setRadioIndicationUpdateMode(filters, mode);
6477 } finally {
6478 Binder.restoreCallingIdentity(identity);
6479 }
Jack Yu4c988042018-02-27 15:30:01 -08006480 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006481
6482 /**
goneil47ffb6e2018-04-06 15:40:58 -07006483 * A test API to reload the UICC profile.
6484 *
6485 * <p>Requires that the calling app has permission
6486 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6487 * @hide
6488 */
6489 @Override
6490 public void refreshUiccProfile(int subId) {
6491 enforceModifyPermission();
6492
6493 final long identity = Binder.clearCallingIdentity();
6494 try {
6495 Phone phone = getPhone(subId);
6496 if (phone == null) {
6497 return;
6498 }
6499 UiccCard uiccCard = phone.getUiccCard();
6500 if (uiccCard == null) {
6501 return;
6502 }
6503 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6504 if (uiccProfile == null) {
6505 return;
6506 }
6507 uiccProfile.refresh();
6508 } finally {
6509 Binder.restoreCallingIdentity(identity);
6510 }
6511 }
6512
6513 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006514 * Returns false if the mobile data is disabled by default, otherwise return true.
6515 */
6516 private boolean getDefaultDataEnabled() {
6517 return "true".equalsIgnoreCase(
6518 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
6519 }
6520
6521 /**
6522 * Returns true if the data roaming is enabled by default, i.e the system property
6523 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
6524 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
6525 */
6526 private boolean getDefaultDataRoamingEnabled(int subId) {
6527 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006528 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006529 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
6530 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
6531 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
6532 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
6533 return isDataRoamingEnabled;
6534 }
6535
6536 /**
6537 * Returns the default network type for the given {@code subId}, if the default network type is
6538 * not set, return {@link Phone#PREFERRED_NT_MODE}.
6539 */
6540 private int getDefaultNetworkType(int subId) {
6541 return Integer.parseInt(
6542 TelephonyManager.getTelephonyProperty(
6543 mSubscriptionController.getPhoneId(subId),
6544 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
6545 String.valueOf(Phone.PREFERRED_NT_MODE)));
6546 }
fionaxua13278b2018-03-21 00:08:13 -07006547
6548 @Override
6549 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07006550 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07006551 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006552
6553 final long identity = Binder.clearCallingIdentity();
6554 try {
6555 final Phone phone = getPhone(subId);
6556 if (phone == null) {
6557 loge("setCarrierTestOverride fails with invalid subId: " + subId);
6558 return;
6559 }
chen xueaba88a2019-03-15 13:15:10 -07006560 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
6561 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006562 } finally {
6563 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006564 }
fionaxua13278b2018-03-21 00:08:13 -07006565 }
6566
6567 @Override
6568 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006569 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006570
6571 final long identity = Binder.clearCallingIdentity();
6572 try {
6573 final Phone phone = getPhone(subId);
6574 if (phone == null) {
6575 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
6576 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
6577 }
6578 return phone.getCarrierIdListVersion();
6579 } finally {
6580 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006581 }
fionaxua13278b2018-03-21 00:08:13 -07006582 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07006583
6584 @Override
6585 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
6586 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6587 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
6588 return -1;
6589 }
6590
6591 final long identity = Binder.clearCallingIdentity();
6592 try {
6593 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
6594 } finally {
6595 Binder.restoreCallingIdentity(identity);
6596 }
6597 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006598
6599 @Override
6600 public int getCdmaRoamingMode(int subId) {
6601 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6602 mApp, subId, "getCdmaRoamingMode");
6603
6604 final long identity = Binder.clearCallingIdentity();
6605 try {
6606 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
6607 } finally {
6608 Binder.restoreCallingIdentity(identity);
6609 }
6610 }
6611
6612 @Override
6613 public boolean setCdmaRoamingMode(int subId, int mode) {
6614 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6615 mApp, subId, "setCdmaRoamingMode");
6616
6617 final long identity = Binder.clearCallingIdentity();
6618 try {
6619 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
6620 } finally {
6621 Binder.restoreCallingIdentity(identity);
6622 }
6623 }
6624
6625 @Override
6626 public boolean setCdmaSubscriptionMode(int subId, int mode) {
6627 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6628 mApp, subId, "setCdmaSubscriptionMode");
6629
6630 final long identity = Binder.clearCallingIdentity();
6631 try {
6632 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
6633 } finally {
6634 Binder.restoreCallingIdentity(identity);
6635 }
6636 }
Makoto Onukida3bf792018-09-18 16:06:29 -07006637
6638 private void ensureUserRunning(int userId) {
6639 if (!mUserManager.isUserRunning(userId)) {
6640 throw new IllegalStateException("User " + userId + " does not exist or not running");
6641 }
6642 }
6643
6644 /**
6645 * Returns a list of SMS apps on a given user.
6646 *
6647 * Only the shell user (UID 2000 or 0) can call it.
6648 * Target user must be running.
6649 */
6650 @Override
6651 public String[] getSmsApps(int userId) {
6652 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
6653 ensureUserRunning(userId);
6654
6655 final Collection<SmsApplicationData> apps =
6656 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
6657
6658 String[] ret = new String[apps.size()];
6659 int i = 0;
6660 for (SmsApplicationData app : apps) {
6661 ret[i++] = app.mPackageName;
6662 }
6663 return ret;
6664 }
6665
6666 /**
6667 * Returns the default SMS app package name on a given user.
6668 *
6669 * Only the shell user (UID 2000 or 0) can call it.
6670 * Target user must be running.
6671 */
6672 @Override
6673 public String getDefaultSmsApp(int userId) {
6674 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
6675 ensureUserRunning(userId);
6676
6677 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
6678 /* updateIfNeeded= */ true, userId);
6679 return cn == null ? null : cn.getPackageName();
6680 }
6681
6682 /**
6683 * Set a package as the default SMS app on a given user.
6684 *
6685 * Only the shell user (UID 2000 or 0) can call it.
6686 * Target user must be running.
6687 */
6688 @Override
6689 public void setDefaultSmsApp(int userId, String packageName) {
6690 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
6691 ensureUserRunning(userId);
6692
6693 boolean found = false;
6694 for (String pkg : getSmsApps(userId)) {
6695 if (TextUtils.equals(packageName, pkg)) {
6696 found = true;
6697 break;
6698 }
6699 }
6700 if (!found) {
6701 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
6702 }
6703
6704 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
6705 }
sqianc5eccab2018-10-19 18:46:41 -07006706
6707 @Override
sqian8c685422019-02-22 15:55:18 -08006708 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
sqianc5eccab2018-10-19 18:46:41 -07006709 String callingPackage) {
sqian11b7a0e2018-12-05 18:48:28 -08006710 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
sqian8c685422019-02-22 15:55:18 -08006711 mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08006712 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6713 }
6714 final long identity = Binder.clearCallingIdentity();
6715 try {
sqian854d44b2018-12-12 16:48:18 -08006716 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
6717 for (Phone phone: PhoneFactory.getPhones()) {
6718 if (phone.getEmergencyNumberTracker() != null
6719 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
6720 emergencyNumberListInternal.put(
6721 phone.getSubId(),
6722 phone.getEmergencyNumberTracker().getEmergencyNumberList());
6723 }
sqian11b7a0e2018-12-05 18:48:28 -08006724 }
sqian854d44b2018-12-12 16:48:18 -08006725 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08006726 } finally {
6727 Binder.restoreCallingIdentity(identity);
6728 }
sqianc5eccab2018-10-19 18:46:41 -07006729 }
6730
6731 @Override
sqian8c685422019-02-22 15:55:18 -08006732 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006733 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08006734 if (!exactMatch) {
6735 TelephonyPermissions
6736 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08006737 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08006738 }
6739 final long identity = Binder.clearCallingIdentity();
6740 try {
sqian854d44b2018-12-12 16:48:18 -08006741 for (Phone phone: PhoneFactory.getPhones()) {
6742 if (phone.getEmergencyNumberTracker() != null
6743 && phone.getEmergencyNumberTracker() != null) {
6744 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
6745 number, exactMatch)) {
6746 return true;
sqian11b7a0e2018-12-05 18:48:28 -08006747 }
6748 }
sqian11b7a0e2018-12-05 18:48:28 -08006749 }
6750 return false;
6751 } finally {
6752 Binder.restoreCallingIdentity(identity);
6753 }
6754 }
6755
sqianf4ca7ed2019-01-15 18:32:07 -08006756 /**
6757 * Update emergency number list for test mode.
6758 */
6759 @Override
6760 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
6761 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6762 "updateEmergencyNumberListTestMode");
6763
6764 final long identity = Binder.clearCallingIdentity();
6765 try {
6766 for (Phone phone: PhoneFactory.getPhones()) {
6767 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6768 if (tracker != null) {
6769 tracker.executeEmergencyNumberTestModeCommand(action, num);
6770 }
6771 }
6772 } finally {
6773 Binder.restoreCallingIdentity(identity);
6774 }
6775 }
6776
6777 /**
6778 * Get the full emergency number list for test mode.
6779 */
6780 @Override
6781 public List<String> getEmergencyNumberListTestMode() {
6782 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6783 "getEmergencyNumberListTestMode");
6784
6785 final long identity = Binder.clearCallingIdentity();
6786 try {
6787 Set<String> emergencyNumbers = new HashSet<>();
6788 for (Phone phone: PhoneFactory.getPhones()) {
6789 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6790 if (tracker != null) {
6791 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
6792 emergencyNumbers.add(num.getNumber());
6793 }
6794 }
6795 }
6796 return new ArrayList<>(emergencyNumbers);
6797 } finally {
6798 Binder.restoreCallingIdentity(identity);
6799 }
6800 }
6801
chen xud6b45bd2018-10-30 22:27:10 -07006802 @Override
6803 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
6804 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
6805 Phone phone = getPhone(subId);
6806 if (phone == null) {
6807 return null;
6808 }
6809 final long identity = Binder.clearCallingIdentity();
6810 try {
6811 UiccProfile profile = UiccController.getInstance()
6812 .getUiccProfileForPhone(phone.getPhoneId());
6813 if (profile != null) {
6814 return profile.getCertsFromCarrierPrivilegeAccessRules();
6815 }
6816 } finally {
6817 Binder.restoreCallingIdentity(identity);
6818 }
6819 return null;
6820 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08006821
6822 /**
6823 * Enable or disable a modem stack.
6824 */
6825 @Override
6826 public boolean enableModemForSlot(int slotIndex, boolean enable) {
6827 enforceModifyPermission();
6828
6829 final long identity = Binder.clearCallingIdentity();
6830 try {
6831 Phone phone = PhoneFactory.getPhone(slotIndex);
6832 if (phone == null) {
6833 return false;
6834 } else {
6835 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
6836 }
6837 } finally {
6838 Binder.restoreCallingIdentity(identity);
6839 }
6840 }
Michelecea4cf22018-12-21 15:00:11 -08006841
Malcolm Chen4bcd9822019-03-27 18:34:05 -07006842 /**
6843 * Whether a modem stack is enabled or not.
6844 */
6845 @Override
6846 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage) {
6847 Phone phone = PhoneFactory.getPhone(slotIndex);
6848 if (phone == null) return false;
6849
6850 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6851 mApp, phone.getSubId(), callingPackage, "isModemEnabledForSlot")) {
6852 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6853 }
6854
6855 final long identity = Binder.clearCallingIdentity();
6856 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07006857 try {
6858 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
6859 } catch (NoSuchElementException ex) {
6860 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
6861 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07006862 } finally {
6863 Binder.restoreCallingIdentity(identity);
6864 }
6865 }
6866
Michelecea4cf22018-12-21 15:00:11 -08006867 @Override
Michele0ea7d782019-03-19 14:58:42 -07006868 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08006869 enforceModifyPermission();
6870
6871 final long identity = Binder.clearCallingIdentity();
6872 try {
6873 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07006874 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08006875 .commit();
6876 } finally {
6877 Binder.restoreCallingIdentity(identity);
6878 }
6879 }
6880
6881 @Override
Michele0ea7d782019-03-19 14:58:42 -07006882 @TelephonyManager.IsMultiSimSupportedResult
6883 public int isMultiSimSupported(String callingPackage) {
Michele4245e952019-02-04 11:36:23 -08006884 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Michele0ea7d782019-03-19 14:58:42 -07006885 getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) {
6886 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08006887 }
Michelecea4cf22018-12-21 15:00:11 -08006888
6889 final long identity = Binder.clearCallingIdentity();
6890 try {
Michele0ea7d782019-03-19 14:58:42 -07006891 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08006892 } finally {
6893 Binder.restoreCallingIdentity(identity);
6894 }
6895 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006896
Michele0ea7d782019-03-19 14:58:42 -07006897 @TelephonyManager.IsMultiSimSupportedResult
6898 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08006899 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
6900 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
6901 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07006902 loge("isMultiSimSupportedInternal: requires at least 2 cards");
6903 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006904 }
6905 // Check if the hardware supports multisim functionality. If usage of multisim is not
6906 // supported by the modem, indicate that it is restricted.
6907 PhoneCapability staticCapability =
6908 mPhoneConfigurationManager.getStaticPhoneCapability();
6909 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07006910 loge("isMultiSimSupportedInternal: no static configuration available");
6911 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006912 }
6913 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07006914 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
6915 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006916 }
6917 // Check if support of multiple SIMs is restricted by carrier
6918 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07006919 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08006920 }
6921
Michele0ea7d782019-03-19 14:58:42 -07006922 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08006923 }
6924
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006925 /**
6926 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08006927 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
6928 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
6929 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006930 * @param numOfSims number of active sims we want to switch to
6931 */
6932 @Override
6933 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08006934 if (numOfSims == 1) {
6935 enforceModifyPermission();
6936 } else {
6937 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6938 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
6939 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006940 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08006941
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006942 try {
Michele30b57b22019-03-01 12:01:14 -08006943 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07006944 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08006945 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
6946 return;
6947 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006948 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
6949 } finally {
6950 Binder.restoreCallingIdentity(identity);
6951 }
6952 }
6953
6954 /**
chen xub4baa772019-04-03 10:23:41 -07006955 * Get whether making changes to modem configurations will trigger reboot.
6956 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08006957 */
6958 @Override
chen xub4baa772019-04-03 10:23:41 -07006959 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage) {
6960 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6961 mApp, subId, callingPackage, "doesSwitchMultiSimConfigTriggerReboot")) {
6962 return false;
6963 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08006964 final long identity = Binder.clearCallingIdentity();
6965 try {
6966 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
6967 } finally {
6968 Binder.restoreCallingIdentity(identity);
6969 }
6970 }
6971
Nathan Harold29f5f052019-02-15 13:41:57 -08006972 private void updateModemStateMetrics() {
6973 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
6974 // TODO: check the state for each modem if the api is ready.
6975 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
6976 }
6977
Pengquan Meng3889a572019-01-23 11:16:29 -08006978 @Override
6979 public int[] getSlotsMapping() {
6980 enforceReadPrivilegedPermission("getSlotsMapping");
6981
6982 final long identity = Binder.clearCallingIdentity();
6983 try {
6984 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
6985 // All logical slots should have a mapping to a physical slot.
6986 int[] logicalSlotsMapping = new int[phoneCount];
6987 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
6988 for (int i = 0; i < slotInfos.length; i++) {
6989 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
6990 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
6991 }
6992 }
6993 return logicalSlotsMapping;
6994 } finally {
6995 Binder.restoreCallingIdentity(identity);
6996 }
6997 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08006998
6999 /**
7000 * Get the IRadio HAL Version
7001 */
7002 @Override
7003 public int getRadioHalVersion() {
7004 Phone phone = getDefaultPhone();
7005 if (phone == null) return -1;
7006 HalVersion hv = phone.getHalVersion();
7007 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7008 return hv.major * 100 + hv.minor;
7009 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007010
7011 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007012 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7013 * corresponding network requests on a subId.
7014 *
7015 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007016 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007017 * 2) APN is un-metered for this subscription, or
7018 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
7019 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on.
7020 *
7021 * @return whether data is allowed for a apn type.
7022 *
7023 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007024 */
7025 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007026 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007027 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Malcolm Chene5ad5792019-04-18 13:51:02 -07007028 mApp, subId, callingPackage, "isDataEnabledForApn")) {
7029 throw new SecurityException("Needs READ_PHONE_STATE for isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007030 }
7031
7032 // Now that all security checks passes, perform the operation as ourselves.
7033 final long identity = Binder.clearCallingIdentity();
7034 try {
7035 Phone phone = getPhone(subId);
7036 if (phone == null) return false;
7037
7038 boolean isMetered = ApnSettingUtils.isMeteredApnType(ApnSetting.getApnTypeString(
Malcolm Chene5ad5792019-04-18 13:51:02 -07007039 apnType), phone);
7040 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7041 } finally {
7042 Binder.restoreCallingIdentity(identity);
7043 }
7044 }
7045
7046 @Override
7047 public boolean isApnMetered(int apnType, int subId) {
7048 enforceReadPrivilegedPermission("isApnMetered");
7049
7050 // Now that all security checks passes, perform the operation as ourselves.
7051 final long identity = Binder.clearCallingIdentity();
7052 try {
7053 Phone phone = getPhone(subId);
7054 if (phone == null) return true; // By default return true.
7055
7056 return ApnSettingUtils.isMeteredApnType(ApnSetting.getApnTypeString(
7057 apnType), phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007058 } finally {
7059 Binder.restoreCallingIdentity(identity);
7060 }
7061 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007062}