blob: a350f1464087edcad8f849b693ce07f1d3d78ab3 [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
Nathan Harold32e84c42019-05-09 10:13:47 -07002142
2143 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002144 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2145
2146 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2147 }
2148
2149 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002150 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002151 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002152 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002153
2154 final long identity = Binder.clearCallingIdentity();
2155 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002156 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002157 } finally {
2158 Binder.restoreCallingIdentity(identity);
2159 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002160 }
2161
Shishir Agrawala9f32182016-04-12 12:00:16 -07002162 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002163 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002164 Phone phone = PhoneFactory.getPhone(slotIndex);
2165 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002166 return null;
2167 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002168 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002169 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2170 callingPackage, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002171 return null;
2172 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002173
2174 final long identity = Binder.clearCallingIdentity();
2175 try {
2176 return phone.getImei();
2177 } finally {
2178 Binder.restoreCallingIdentity(identity);
2179 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002180 }
2181
2182 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002183 public String getTypeAllocationCodeForSlot(int slotIndex) {
2184 Phone phone = PhoneFactory.getPhone(slotIndex);
2185 String tac = null;
2186 if (phone != null) {
2187 String imei = phone.getImei();
2188 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2189 }
2190 return tac;
2191 }
2192
2193 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002194 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002195 Phone phone = PhoneFactory.getPhone(slotIndex);
2196 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002197 return null;
2198 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002199
Jeff Davidson913390f2018-02-23 17:11:49 -08002200 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002201 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2202 callingPackage, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002203 return null;
2204 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002205
2206 final long identity = Binder.clearCallingIdentity();
2207 try {
2208 return phone.getMeid();
2209 } finally {
2210 Binder.restoreCallingIdentity(identity);
2211 }
Jack Yu2af8d712017-03-15 17:14:14 -07002212 }
2213
2214 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002215 public String getManufacturerCodeForSlot(int slotIndex) {
2216 Phone phone = PhoneFactory.getPhone(slotIndex);
2217 String manufacturerCode = null;
2218 if (phone != null) {
2219 String meid = phone.getMeid();
2220 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2221 }
2222 return manufacturerCode;
2223 }
2224
2225 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002226 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002227 Phone phone = PhoneFactory.getPhone(slotIndex);
2228 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002229 return null;
2230 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002231 int subId = phone.getSubId();
2232 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2233 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2234 return null;
2235 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002236
2237 final long identity = Binder.clearCallingIdentity();
2238 try {
2239 return phone.getDeviceSvn();
2240 } finally {
2241 Binder.restoreCallingIdentity(identity);
2242 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002243 }
2244
fionaxu43304da2017-11-27 22:51:16 -08002245 @Override
2246 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002247 final long identity = Binder.clearCallingIdentity();
2248 try {
2249 final Phone phone = getPhone(subId);
2250 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2251 } finally {
2252 Binder.restoreCallingIdentity(identity);
2253 }
fionaxu43304da2017-11-27 22:51:16 -08002254 }
2255
2256 @Override
2257 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002258 final long identity = Binder.clearCallingIdentity();
2259 try {
2260 final Phone phone = getPhone(subId);
2261 return phone == null ? null : phone.getCarrierName();
2262 } finally {
2263 Binder.restoreCallingIdentity(identity);
2264 }
fionaxu43304da2017-11-27 22:51:16 -08002265 }
2266
calvinpanffe225e2018-11-01 19:43:06 +08002267 @Override
chen xu0026ca62019-03-06 15:28:50 -08002268 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002269 final long identity = Binder.clearCallingIdentity();
2270 try {
2271 final Phone phone = getPhone(subId);
2272 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002273 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002274 } finally {
2275 Binder.restoreCallingIdentity(identity);
2276 }
2277 }
2278
2279 @Override
chen xu0026ca62019-03-06 15:28:50 -08002280 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002281 final long identity = Binder.clearCallingIdentity();
2282 try {
2283 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002284 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002285 } finally {
2286 Binder.restoreCallingIdentity(identity);
2287 }
2288 }
2289
chen xu651eec72018-11-11 19:03:44 -08002290 @Override
chen xu864e11c2018-12-06 22:10:03 -08002291 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2292 if (!isSubscriptionMccMnc) {
2293 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2294 }
chen xu651eec72018-11-11 19:03:44 -08002295 final Phone phone = PhoneFactory.getPhone(slotIndex);
2296 if (phone == null) {
2297 return TelephonyManager.UNKNOWN_CARRIER_ID;
2298 }
2299 final long identity = Binder.clearCallingIdentity();
2300 try {
2301 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2302 } finally {
2303 Binder.restoreCallingIdentity(identity);
2304 }
2305 }
2306
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002307 //
2308 // Internal helper methods.
2309 //
2310
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002311 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002312 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2313 *
2314 * @throws SecurityException if the caller does not have the required permission
2315 */
2316 private void enforceModifyPermission() {
2317 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2318 }
2319
2320 /**
2321 * Make sure the caller has the CALL_PHONE permission.
2322 *
2323 * @throws SecurityException if the caller does not have the required permission
2324 */
2325 private void enforceCallPermission() {
2326 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2327 }
2328
Stuart Scott8eef64f2015-04-08 15:13:54 -07002329 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002330 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002331 "ConnectivityService");
2332 }
2333
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002334 private String createTelUrl(String number) {
2335 if (TextUtils.isEmpty(number)) {
2336 return null;
2337 }
2338
Jake Hambye994d462014-02-03 13:10:13 -08002339 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002340 }
2341
Ihab Awadf9e92732013-12-05 18:02:52 -08002342 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002343 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2344 }
2345
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002346 private static void logv(String msg) {
2347 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2348 }
2349
Ihab Awadf9e92732013-12-05 18:02:52 -08002350 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002351 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2352 }
2353
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002354 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002355 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002356 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002357 }
2358
Sanket Padawe356d7632015-06-22 14:03:32 -07002359 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002360 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002361 final long identity = Binder.clearCallingIdentity();
2362 try {
2363 final Phone phone = PhoneFactory.getPhone(slotIndex);
2364 if (phone == null) {
2365 return PhoneConstants.PHONE_TYPE_NONE;
2366 } else {
2367 return phone.getPhoneType();
2368 }
2369 } finally {
2370 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002371 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002372 }
2373
2374 /**
2375 * Returns the CDMA ERI icon index to display
2376 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002377 @Override
2378 public int getCdmaEriIconIndex(String callingPackage) {
2379 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002380 }
2381
Sanket Padawe356d7632015-06-22 14:03:32 -07002382 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002383 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002384 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002385 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002386 return -1;
2387 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002388
2389 final long identity = Binder.clearCallingIdentity();
2390 try {
2391 final Phone phone = getPhone(subId);
2392 if (phone != null) {
2393 return phone.getCdmaEriIconIndex();
2394 } else {
2395 return -1;
2396 }
2397 } finally {
2398 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002399 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002400 }
2401
2402 /**
2403 * Returns the CDMA ERI icon mode,
2404 * 0 - ON
2405 * 1 - FLASHING
2406 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002407 @Override
2408 public int getCdmaEriIconMode(String callingPackage) {
2409 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002410 }
2411
Sanket Padawe356d7632015-06-22 14:03:32 -07002412 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002413 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002414 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002415 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002416 return -1;
2417 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002418
2419 final long identity = Binder.clearCallingIdentity();
2420 try {
2421 final Phone phone = getPhone(subId);
2422 if (phone != null) {
2423 return phone.getCdmaEriIconMode();
2424 } else {
2425 return -1;
2426 }
2427 } finally {
2428 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002429 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002430 }
2431
2432 /**
2433 * Returns the CDMA ERI text,
2434 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002435 @Override
2436 public String getCdmaEriText(String callingPackage) {
2437 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002438 }
2439
Sanket Padawe356d7632015-06-22 14:03:32 -07002440 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002441 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002442 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002443 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002444 return null;
2445 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002446
2447 final long identity = Binder.clearCallingIdentity();
2448 try {
2449 final Phone phone = getPhone(subId);
2450 if (phone != null) {
2451 return phone.getCdmaEriText();
2452 } else {
2453 return null;
2454 }
2455 } finally {
2456 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002457 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002458 }
2459
2460 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002461 * Returns the CDMA MDN.
2462 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002463 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002464 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002465 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2466 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002467
2468 final long identity = Binder.clearCallingIdentity();
2469 try {
2470 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002471 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002472 return phone.getLine1Number();
2473 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002474 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002475 return null;
2476 }
2477 } finally {
2478 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002479 }
2480 }
2481
2482 /**
2483 * Returns the CDMA MIN.
2484 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002485 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002486 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002487 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2488 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002489
2490 final long identity = Binder.clearCallingIdentity();
2491 try {
2492 final Phone phone = getPhone(subId);
2493 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2494 return phone.getCdmaMin();
2495 } else {
2496 return null;
2497 }
2498 } finally {
2499 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002500 }
2501 }
2502
Hall Liud892bec2018-11-30 14:51:45 -08002503 @Override
2504 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2505 INumberVerificationCallback callback, String callingPackage) {
2506 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2507 != PERMISSION_GRANTED) {
2508 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2509 }
2510 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2511
2512 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2513 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2514 throw new SecurityException("Calling package must be configured in the device config");
2515 }
2516
2517 if (range == null) {
2518 throw new NullPointerException("Range must be non-null");
2519 }
2520
2521 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002522 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002523
2524 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2525 }
2526
Junda Liuca05d5d2014-08-14 22:36:34 -07002527 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002528 * Returns true if CDMA provisioning needs to run.
2529 */
2530 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002531 final long identity = Binder.clearCallingIdentity();
2532 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002533 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002534 } finally {
2535 Binder.restoreCallingIdentity(identity);
2536 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002537 }
2538
2539 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002540 * Sets the voice mail number of a given subId.
2541 */
2542 @Override
2543 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002544 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002545
2546 final long identity = Binder.clearCallingIdentity();
2547 try {
2548 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2549 new Pair<String, String>(alphaTag, number), new Integer(subId));
2550 return success;
2551 } finally {
2552 Binder.restoreCallingIdentity(identity);
2553 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002554 }
2555
Ta-wei Yen87c49842016-05-13 21:19:52 -07002556 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002557 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2558 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002559 String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002560 if (!TextUtils.equals(callingPackage, systemDialer)) {
2561 throw new SecurityException("caller must be system dialer");
2562 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002563
2564 final long identity = Binder.clearCallingIdentity();
2565 try {
2566 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2567 if (phoneAccountHandle == null) {
2568 return null;
2569 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002570 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002571 } finally {
2572 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002573 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002574 }
2575
2576 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002577 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002578 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002579 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002580 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002581 return null;
2582 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002583
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002584 final long identity = Binder.clearCallingIdentity();
2585 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002586 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002587 } finally {
2588 Binder.restoreCallingIdentity(identity);
2589 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002590 }
2591
2592 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002593 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2594 VisualVoicemailSmsFilterSettings settings) {
2595 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002596
2597 final long identity = Binder.clearCallingIdentity();
2598 try {
2599 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002600 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002601 } finally {
2602 Binder.restoreCallingIdentity(identity);
2603 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002604 }
2605
2606 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002607 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2608 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002609
2610 final long identity = Binder.clearCallingIdentity();
2611 try {
2612 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002613 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002614 } finally {
2615 Binder.restoreCallingIdentity(identity);
2616 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002617 }
2618
2619 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002620 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2621 String callingPackage, int subId) {
2622 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002623
2624 final long identity = Binder.clearCallingIdentity();
2625 try {
2626 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002627 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002628 } finally {
2629 Binder.restoreCallingIdentity(identity);
2630 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002631 }
2632
2633 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002634 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002635 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002636
2637 final long identity = Binder.clearCallingIdentity();
2638 try {
2639 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002640 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002641 } finally {
2642 Binder.restoreCallingIdentity(identity);
2643 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002644 }
2645
2646 @Override
2647 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2648 String number, int port, String text, PendingIntent sentIntent) {
2649 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002650 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002651 enforceSendSmsPermission();
2652 // Make the calls as the phone process.
2653 final long identity = Binder.clearCallingIdentity();
2654 try {
2655 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2656 if (port == 0) {
2657 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2658 sentIntent, null, false);
2659 } else {
2660 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2661 smsManager.sendDataMessageWithSelfPermissions(number, null,
2662 (short) port, data, sentIntent, null);
2663 }
2664 } finally {
2665 Binder.restoreCallingIdentity(identity);
2666 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002667 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002668 /**
fionaxu0152e512016-11-14 13:36:14 -08002669 * Sets the voice activation state of a given subId.
2670 */
2671 @Override
2672 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002673 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2674 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002675
2676 final long identity = Binder.clearCallingIdentity();
2677 try {
2678 final Phone phone = getPhone(subId);
2679 if (phone != null) {
2680 phone.setVoiceActivationState(activationState);
2681 } else {
2682 loge("setVoiceActivationState fails with invalid subId: " + subId);
2683 }
2684 } finally {
2685 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002686 }
2687 }
2688
2689 /**
2690 * Sets the data activation state of a given subId.
2691 */
2692 @Override
2693 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002694 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2695 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002696
2697 final long identity = Binder.clearCallingIdentity();
2698 try {
2699 final Phone phone = getPhone(subId);
2700 if (phone != null) {
2701 phone.setDataActivationState(activationState);
2702 } else {
2703 loge("setVoiceActivationState fails with invalid subId: " + subId);
2704 }
2705 } finally {
2706 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002707 }
2708 }
2709
2710 /**
2711 * Returns the voice activation state of a given subId.
2712 */
2713 @Override
2714 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002715 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002716
fionaxu0152e512016-11-14 13:36:14 -08002717 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002718 final long identity = Binder.clearCallingIdentity();
2719 try {
2720 if (phone != null) {
2721 return phone.getVoiceActivationState();
2722 } else {
2723 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2724 }
2725 } finally {
2726 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002727 }
2728 }
2729
2730 /**
2731 * Returns the data activation state of a given subId.
2732 */
2733 @Override
2734 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002735 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002736
fionaxu0152e512016-11-14 13:36:14 -08002737 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002738 final long identity = Binder.clearCallingIdentity();
2739 try {
2740 if (phone != null) {
2741 return phone.getDataActivationState();
2742 } else {
2743 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2744 }
2745 } finally {
2746 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002747 }
2748 }
2749
2750 /**
Wink Saville36469e72014-06-11 15:17:00 -07002751 * Returns the unread count of voicemails for a subId
2752 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002753 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002754 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2755 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2756 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2757 return 0;
2758 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002759 final long identity = Binder.clearCallingIdentity();
2760 try {
2761 final Phone phone = getPhone(subId);
2762 if (phone != null) {
2763 return phone.getVoiceMessageCount();
2764 } else {
2765 return 0;
2766 }
2767 } finally {
2768 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002769 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002770 }
2771
2772 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002773 * returns true, if the device is in a state where both voice and data
2774 * are supported simultaneously. This can change based on location or network condition.
2775 */
2776 @Override
2777 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002778 final long identity = Binder.clearCallingIdentity();
2779 try {
2780 final Phone phone = getPhone(subId);
2781 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2782 } finally {
2783 Binder.restoreCallingIdentity(identity);
2784 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002785 }
2786
2787 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002788 * Send the dialer code if called from the current default dialer or the caller has
2789 * carrier privilege.
2790 * @param inputCode The dialer code to send
2791 */
2792 @Override
2793 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002794 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002795 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002796 String defaultDialer = TelecomManager.from(defaultPhone.getContext())
2797 .getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002798 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002799 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2800 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002801 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002802
2803 final long identity = Binder.clearCallingIdentity();
2804 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002805 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002806 } finally {
2807 Binder.restoreCallingIdentity(identity);
2808 }
fionaxu235cc5e2017-03-06 22:25:57 -08002809 }
2810
2811 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002812 * Returns the data network type.
2813 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002814 *
2815 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2816 */
2817 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002818 public int getNetworkType() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002819 final long identity = Binder.clearCallingIdentity();
2820 try {
2821 final Phone phone = getPhone(getDefaultSubscription());
2822 if (phone != null) {
2823 return phone.getServiceState().getDataNetworkType();
2824 } else {
2825 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2826 }
2827 } finally {
2828 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002829 }
Wink Saville36469e72014-06-11 15:17:00 -07002830 }
2831
Pengquan Menga1bb6272018-09-06 09:59:22 -07002832 @Override
2833 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002834 if (!isActiveSubscription(subId)) {
2835 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2836 }
2837
Pengquan Menga1bb6272018-09-06 09:59:22 -07002838 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2839 }
2840
Brad Ebinger35c841c2018-10-01 10:40:55 -07002841 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002842 public boolean isInEmergencySmsMode() {
2843 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2844 final long identity = Binder.clearCallingIdentity();
2845 try {
2846 for (Phone phone : PhoneFactory.getPhones()) {
2847 if (phone.isInEmergencySmsMode()) {
2848 return true;
2849 }
2850 }
2851 } finally {
2852 Binder.restoreCallingIdentity(identity);
2853 }
2854 return false;
2855 }
2856
2857 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002858 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2859 throws RemoteException {
2860 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002861 final long token = Binder.clearCallingIdentity();
2862 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002863 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002864 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002865 .addRegistrationCallbackForSubscription(c, subId);
2866 } finally {
2867 Binder.restoreCallingIdentity(token);
2868 }
2869 }
2870
2871 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002872 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2873 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002874 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2875 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2876 }
2877 Binder.withCleanCallingIdentity(() -> {
2878 try {
2879 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002880 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002881 .removeRegistrationCallbackForSubscription(c, subId);
2882 } catch (IllegalArgumentException e) {
2883 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2884 + "is inactive, ignoring unregister.");
2885 // If the subscription is no longer active, just return, since the callback
2886 // will already have been removed internally.
2887 }
2888 });
Brad Ebinger35c841c2018-10-01 10:40:55 -07002889 }
2890
2891 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002892 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2893 throws RemoteException {
2894 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002895 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2896 final long token = Binder.clearCallingIdentity();
2897 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002898 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002899 .addCapabilitiesCallbackForSubscription(c, subId);
2900 } finally {
2901 Binder.restoreCallingIdentity(token);
2902 }
2903 }
2904
2905 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002906 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2907 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002908
2909 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2910 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2911 }
2912 Binder.withCleanCallingIdentity(() -> {
2913 try {
2914 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002915 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002916 .removeCapabilitiesCallbackForSubscription(c, subId);
2917 } catch (IllegalArgumentException e) {
2918 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
2919 + "is inactive, ignoring unregister.");
2920 // If the subscription is no longer active, just return, since the callback
2921 // will already have been removed internally.
2922 }
2923 });
Brad Ebinger35c841c2018-10-01 10:40:55 -07002924 }
2925
2926 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002927 public boolean isCapable(int subId, int capability, int regTech) {
2928 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002929 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2930 final long token = Binder.clearCallingIdentity();
2931 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002932 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002933 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2934 } catch (ImsException e) {
2935 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2936 return false;
Brad Ebinger6b5ac222019-02-04 14:36:52 -08002937 } catch (IllegalArgumentException e) {
2938 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
2939 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07002940 } finally {
2941 Binder.restoreCallingIdentity(token);
2942 }
2943 }
2944
2945 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002946 public boolean isAvailable(int subId, int capability, int regTech) {
2947 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002948 final long token = Binder.clearCallingIdentity();
2949 try {
2950 Phone phone = getPhone(subId);
2951 if (phone == null) return false;
2952 return phone.isImsCapabilityAvailable(capability, regTech);
2953 } finally {
2954 Binder.restoreCallingIdentity(token);
2955 }
2956 }
2957
2958 @Override
2959 public boolean isAdvancedCallingSettingEnabled(int subId) {
2960 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2961 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2962 final long token = Binder.clearCallingIdentity();
2963 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002964 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002965 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2966 } finally {
2967 Binder.restoreCallingIdentity(token);
2968 }
2969 }
2970
2971 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08002972 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002973 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08002974 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002975 final long identity = Binder.clearCallingIdentity();
2976 try {
2977 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002978 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002979 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2980 } finally {
2981 Binder.restoreCallingIdentity(identity);
2982 }
2983 }
2984
2985 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002986 public boolean isVtSettingEnabled(int subId) {
2987 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002988 final long identity = Binder.clearCallingIdentity();
2989 try {
2990 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002991 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002992 getSlotIndexOrException(subId)).isVtEnabledByUser();
2993 } finally {
2994 Binder.restoreCallingIdentity(identity);
2995 }
2996 }
2997
2998 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08002999 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003000 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003001 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003002 final long identity = Binder.clearCallingIdentity();
3003 try {
3004 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003005 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003006 } finally {
3007 Binder.restoreCallingIdentity(identity);
3008 }
3009 }
3010
3011 @Override
3012 public boolean isVoWiFiSettingEnabled(int subId) {
3013 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3014 final long identity = Binder.clearCallingIdentity();
3015 try {
3016 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003017 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003018 getSlotIndexOrException(subId)).isWfcEnabledByUser();
3019 } finally {
3020 Binder.restoreCallingIdentity(identity);
3021 }
3022 }
3023
3024 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003025 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003026 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003027 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003028 final long identity = Binder.clearCallingIdentity();
3029 try {
3030 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003031 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003032 } finally {
3033 Binder.restoreCallingIdentity(identity);
3034 }
3035 }
3036
3037 @Override
3038 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3039 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3040 final long identity = Binder.clearCallingIdentity();
3041 try {
3042 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003043 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003044 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
3045 } finally {
3046 Binder.restoreCallingIdentity(identity);
3047 }
3048 }
3049
3050 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003051 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003052 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003053 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003054 final long identity = Binder.clearCallingIdentity();
3055 try {
3056 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003057 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003058 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
3059 } finally {
3060 Binder.restoreCallingIdentity(identity);
3061 }
3062 }
3063
3064 @Override
3065 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3066 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3067 "setVoWiFiNonPersistent");
3068 final long identity = Binder.clearCallingIdentity();
3069 try {
3070 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003071 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003072 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003073 } finally {
3074 Binder.restoreCallingIdentity(identity);
3075 }
3076 }
3077
3078 @Override
3079 public int getVoWiFiModeSetting(int subId) {
3080 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3081 final long identity = Binder.clearCallingIdentity();
3082 try {
3083 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003084 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003085 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
3086 } finally {
3087 Binder.restoreCallingIdentity(identity);
3088 }
3089 }
3090
3091 @Override
3092 public void setVoWiFiModeSetting(int subId, int mode) {
3093 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3094 "setVoWiFiModeSetting");
3095 final long identity = Binder.clearCallingIdentity();
3096 try {
3097 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003098 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003099 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
3100 } finally {
3101 Binder.restoreCallingIdentity(identity);
3102 }
3103 }
3104
3105 @Override
3106 public int getVoWiFiRoamingModeSetting(int subId) {
3107 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3108 final long identity = Binder.clearCallingIdentity();
3109 try {
3110 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003111 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003112 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
3113 } finally {
3114 Binder.restoreCallingIdentity(identity);
3115 }
3116 }
3117
3118 @Override
3119 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3120 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3121 "setVoWiFiRoamingModeSetting");
3122 final long identity = Binder.clearCallingIdentity();
3123 try {
3124 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003125 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003126 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
3127 } finally {
3128 Binder.restoreCallingIdentity(identity);
3129 }
3130 }
3131
3132 @Override
3133 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3134 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3135 "setRttCapabilityEnabled");
3136 final long identity = Binder.clearCallingIdentity();
3137 try {
3138 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003139 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003140 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3141 } finally {
3142 Binder.restoreCallingIdentity(identity);
3143 }
3144 }
3145
3146 @Override
3147 public boolean isTtyOverVolteEnabled(int subId) {
3148 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3149 final long identity = Binder.clearCallingIdentity();
3150 try {
3151 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003152 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003153 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
3154 } finally {
3155 Binder.restoreCallingIdentity(identity);
3156 }
3157 }
3158
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003159 @Override
3160 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3161 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3162 final long identity = Binder.clearCallingIdentity();
3163 try {
3164 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003165 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003166 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003167 } finally {
3168 Binder.restoreCallingIdentity(identity);
3169 }
3170 }
3171
3172 @Override
3173 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3174 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3175 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003176 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3177 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3178 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003179 try {
3180 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003181 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003182 .removeProvisioningCallbackForSubscription(callback, subId);
3183 } catch (IllegalArgumentException e) {
3184 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3185 + "is inactive, ignoring unregister.");
3186 // If the subscription is no longer active, just return, since the callback will already
3187 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003188 } finally {
3189 Binder.restoreCallingIdentity(identity);
3190 }
3191 }
3192
3193 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003194 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3195 boolean isProvisioned) {
3196 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3197 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3198 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3199 }
3200 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3201 "setProvisioningStatusForCapability");
3202 final long identity = Binder.clearCallingIdentity();
3203 try {
3204 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3205 Phone phone = getPhone(subId);
3206 if (phone == null) {
3207 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3208 + subId);
3209 return;
3210 }
3211 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3212 return;
3213 }
3214
3215 // this capability requires provisioning, route to the correct API.
3216 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3217 switch (capability) {
3218 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3219 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3220 ims.setVolteProvisioned(isProvisioned);
3221 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3222 ims.setWfcProvisioned(isProvisioned);
3223 }
3224 break;
3225 }
3226 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3227 // There is currently no difference in VT provisioning type.
3228 ims.setVtProvisioned(isProvisioned);
3229 break;
3230 }
3231 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3232 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3233 // change the capability of the feature instead if needed.
3234 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3235 == isProvisioned) {
3236 // No change in provisioning.
3237 return;
3238 }
3239 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3240 try {
3241 ims.changeMmTelCapability(capability, tech, isProvisioned);
3242 } catch (ImsException e) {
3243 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3244 + ", Exception" + e.getMessage());
3245 }
3246 break;
3247 }
3248 default: {
3249 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3250 + capability + "', which does not require provisioning.");
3251 }
3252 }
3253
3254 } finally {
3255 Binder.restoreCallingIdentity(identity);
3256 }
3257 }
3258
3259 @Override
3260 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3261 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3262 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3263 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3264 }
3265 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3266 final long identity = Binder.clearCallingIdentity();
3267 try {
3268 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3269 Phone phone = getPhone(subId);
3270 if (phone == null) {
3271 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3272 + subId);
3273 // We will fail with "true" as the provisioning status because this is the default
3274 // if we do not require provisioning.
3275 return true;
3276 }
3277
3278 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3279 return true;
3280 }
3281
3282 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3283 switch (capability) {
3284 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3285 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3286 return ims.isVolteProvisionedOnDevice();
3287 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3288 return ims.isWfcProvisionedOnDevice();
3289 }
3290 // This should never happen, since we are checking tech above to make sure it
3291 // is either LTE or IWLAN.
3292 throw new IllegalArgumentException("Invalid radio technology for voice "
3293 + "capability.");
3294 }
3295 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3296 // There is currently no difference in VT provisioning type.
3297 return ims.isVtProvisionedOnDevice();
3298 }
3299 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3300 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3301 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3302 }
3303 default: {
3304 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3305 + capability + "', which does not require provisioning.");
3306 }
3307 }
3308
3309 } finally {
3310 Binder.restoreCallingIdentity(identity);
3311 }
3312 }
3313
3314 @Override
3315 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3316 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3317 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3318 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3319 }
3320 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3321 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3322 return (provisionedBits & capability) > 0;
3323 }
3324
3325 @Override
3326 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3327 boolean isProvisioned) {
3328 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3329 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3330 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3331 }
3332 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3333 "setProvisioningStatusForCapability");
3334 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3335 // If the current provisioning status for capability already matches isProvisioned,
3336 // do nothing.
3337 if (((provisionedBits & capability) > 0) == isProvisioned) {
3338 return;
3339 }
3340 if (isProvisioned) {
3341 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3342 } else {
3343 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3344 }
3345 }
3346
3347 /**
3348 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3349 * technology. The bitfield should mirror the bitfield defined by
3350 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3351 */
3352 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3353 String key = getMmTelProvisioningKey(subId, tech);
3354 // Default is no capabilities are provisioned.
3355 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3356 }
3357
3358 /**
3359 * Sets the MmTel capability provisioning bitfield (defined by
3360 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3361 * technology specified.
3362 *
3363 * Note: This is a synchronous command and should not be called on UI thread.
3364 */
3365 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3366 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3367 String key = getMmTelProvisioningKey(subId, tech);
3368 editor.putInt(key, newField);
3369 editor.commit();
3370 }
3371
3372 private static String getMmTelProvisioningKey(int subId, int tech) {
3373 // resulting key is provision_ims_mmtel_{subId}_{tech}
3374 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3375 }
3376
3377 /**
3378 * Query CarrierConfig to see if the specified capability requires provisioning for the
3379 * carrier associated with the subscription id.
3380 */
3381 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3382 int capability) {
3383 CarrierConfigManager configManager = new CarrierConfigManager(context);
3384 PersistableBundle c = configManager.getConfigForSubId(subId);
3385 boolean requireUtProvisioning = c.getBoolean(
3386 // By default, this config is true (even if there is no SIM). We also check to make
3387 // sure the subscription needs provisioning here, so we do not need to check for
3388 // the no-SIM case, where we would normally shortcut this to false.
3389 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, true)
3390 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3391 false);
3392 boolean requireVoiceVtProvisioning = c.getBoolean(
3393 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3394
3395 // First check to make sure that the capability requires provisioning.
3396 switch (capability) {
3397 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3398 // intentional fallthrough
3399 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3400 if (requireVoiceVtProvisioning) {
3401 // Voice and Video requires provisioning
3402 return true;
3403 }
3404 break;
3405 }
3406 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3407 if (requireUtProvisioning) {
3408 // UT requires provisioning
3409 return true;
3410 }
3411 break;
3412 }
3413 }
3414 return false;
3415 }
3416
3417 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003418 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003419 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3420 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3421 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003422 enforceReadPrivilegedPermission("getImsProvisioningInt");
3423 final long identity = Binder.clearCallingIdentity();
3424 try {
3425 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003426 int slotId = getSlotIndex(subId);
3427 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3428 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3429 + subId + "' for key:" + key);
3430 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3431 }
3432 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003433 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003434 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3435 + subId + "' for key:" + key);
3436 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003437 } finally {
3438 Binder.restoreCallingIdentity(identity);
3439 }
3440 }
3441
3442 @Override
3443 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003444 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3445 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3446 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003447 enforceReadPrivilegedPermission("getImsProvisioningString");
3448 final long identity = Binder.clearCallingIdentity();
3449 try {
3450 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003451 int slotId = getSlotIndex(subId);
3452 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3453 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3454 + subId + "' for key:" + key);
3455 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3456 }
3457 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003458 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003459 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3460 + subId + "' for key:" + key);
3461 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003462 } finally {
3463 Binder.restoreCallingIdentity(identity);
3464 }
3465 }
3466
3467 @Override
3468 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003469 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3470 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3471 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003472 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3473 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003474 final long identity = Binder.clearCallingIdentity();
3475 try {
3476 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003477 int slotId = getSlotIndex(subId);
3478 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3479 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3480 + subId + "' for key:" + key);
3481 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3482 }
3483 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003484 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003485 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3486 + "' for key:" + key);
3487 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003488 } finally {
3489 Binder.restoreCallingIdentity(identity);
3490 }
3491 }
3492
3493 @Override
3494 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003495 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3496 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3497 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003498 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3499 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003500 final long identity = Binder.clearCallingIdentity();
3501 try {
3502 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003503 int slotId = getSlotIndex(subId);
3504 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3505 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3506 + subId + "' for key:" + key);
3507 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3508 }
3509 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003510 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003511 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3512 + "' for key:" + key);
3513 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003514 } finally {
3515 Binder.restoreCallingIdentity(identity);
3516 }
3517 }
3518
Brad Ebinger35c841c2018-10-01 10:40:55 -07003519 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
3520 int slotId = SubscriptionManager.getSlotIndex(subId);
3521 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003522 throw new IllegalArgumentException("Invalid Subscription Id, subId=" + subId);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003523 }
3524 return slotId;
3525 }
3526
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003527 private int getSlotIndex(int subId) {
3528 int slotId = SubscriptionManager.getSlotIndex(subId);
3529 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3530 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3531 }
3532 return slotId;
3533 }
3534
Wink Saville36469e72014-06-11 15:17:00 -07003535 /**
3536 * Returns the network type for a subId
3537 */
3538 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003539 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003540 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003541 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003542 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3543 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003544
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003545 final long identity = Binder.clearCallingIdentity();
3546 try {
3547 final Phone phone = getPhone(subId);
3548 if (phone != null) {
3549 return phone.getServiceState().getDataNetworkType();
3550 } else {
3551 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3552 }
3553 } finally {
3554 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003555 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003556 }
3557
3558 /**
3559 * Returns the data network type
3560 */
3561 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003562 public int getDataNetworkType(String callingPackage) {
3563 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003564 }
3565
3566 /**
3567 * Returns the data network type for a subId
3568 */
3569 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003570 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003571 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003572 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003573 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3574 }
3575
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003576 final long identity = Binder.clearCallingIdentity();
3577 try {
3578 final Phone phone = getPhone(subId);
3579 if (phone != null) {
3580 return phone.getServiceState().getDataNetworkType();
3581 } else {
3582 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3583 }
3584 } finally {
3585 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003586 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003587 }
3588
3589 /**
Wink Saville36469e72014-06-11 15:17:00 -07003590 * Returns the Voice network type for a subId
3591 */
3592 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003593 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003594 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003595 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003596 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3597 }
3598
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003599 final long identity = Binder.clearCallingIdentity();
3600 try {
3601 final Phone phone = getPhone(subId);
3602 if (phone != null) {
3603 return phone.getServiceState().getVoiceNetworkType();
3604 } else {
3605 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3606 }
3607 } finally {
3608 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003609 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003610 }
3611
3612 /**
3613 * @return true if a ICC card is present
3614 */
3615 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003616 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003617 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3618 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003619 }
3620
3621 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003622 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003623 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003624 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003625 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003626 final long identity = Binder.clearCallingIdentity();
3627 try {
3628 final Phone phone = PhoneFactory.getPhone(slotIndex);
3629 if (phone != null) {
3630 return phone.getIccCard().hasIccCard();
3631 } else {
3632 return false;
3633 }
3634 } finally {
3635 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003636 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003637 }
3638
3639 /**
3640 * Return if the current radio is LTE on CDMA. This
3641 * is a tri-state return value as for a period of time
3642 * the mode may be unknown.
3643 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003644 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003645 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003646 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003647 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003648 @Override
3649 public int getLteOnCdmaMode(String callingPackage) {
3650 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003651 }
3652
Sanket Padawe356d7632015-06-22 14:03:32 -07003653 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003654 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003655 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003656 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003657 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3658 }
3659
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003660 final long identity = Binder.clearCallingIdentity();
3661 try {
3662 final Phone phone = getPhone(subId);
3663 if (phone == null) {
3664 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3665 } else {
3666 return phone.getLteOnCdmaMode();
3667 }
3668 } finally {
3669 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003670 }
Wink Saville36469e72014-06-11 15:17:00 -07003671 }
3672
Wink Saville36469e72014-06-11 15:17:00 -07003673 /**
3674 * {@hide}
3675 * Returns Default subId, 0 in the case of single standby.
3676 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003677 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003678 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003679 }
3680
Shishir Agrawala9f32182016-04-12 12:00:16 -07003681 private int getSlotForDefaultSubscription() {
3682 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3683 }
3684
Wink Savilleb564aae2014-10-23 10:18:09 -07003685 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003686 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003687 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003688
Pengquan Menge92a50d2018-09-21 15:54:48 -07003689 private boolean isActiveSubscription(int subId) {
3690 return mSubscriptionController.isActiveSubId(subId);
3691 }
3692
Ihab Awadf2177b72013-11-25 13:33:23 -08003693 /**
3694 * @see android.telephony.TelephonyManager.WifiCallingChoices
3695 */
3696 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003697 final long identity = Binder.clearCallingIdentity();
3698 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003699 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003700 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3701 getWhenToMakeWifiCallsDefaultPreference());
3702 } finally {
3703 Binder.restoreCallingIdentity(identity);
3704 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003705 }
3706
3707 /**
3708 * @see android.telephony.TelephonyManager.WifiCallingChoices
3709 */
3710 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003711 final long identity = Binder.clearCallingIdentity();
3712 try {
3713 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003714 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003715 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3716 } finally {
3717 Binder.restoreCallingIdentity(identity);
3718 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003719 }
3720
Sailesh Nepald1e68152013-12-12 19:08:02 -08003721 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003722 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003723 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003724 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003725
Jordan Liu4c733742019-02-28 12:03:40 -08003726 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
3727 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
3728 if (phoneId == -1) {
3729 throw new IllegalArgumentException("Given slot index: " + slotIndex
3730 + " does not correspond to an active phone");
3731 }
3732 return PhoneFactory.getPhone(phoneId);
3733 }
3734
Shishir Agrawal566b7612013-10-28 14:41:00 -07003735 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003736 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3737 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003738 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3739 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003740 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08003741 if (DBG) {
3742 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3743 }
3744 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
3745 p2);
3746 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003747
Jordan Liu4c733742019-02-28 12:03:40 -08003748
3749 @Override
3750 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
3751 int slotIndex, String callingPackage, String aid, int p2) {
3752 enforceModifyPermission();
3753 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3754 if (DBG) {
3755 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
3756 }
3757 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3758 callingPackage, aid, p2);
3759 }
3760
3761 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
3762 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003763 final long identity = Binder.clearCallingIdentity();
3764 try {
3765 if (TextUtils.equals(ISDR_AID, aid)) {
3766 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003767 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3768 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003769 if (bestComponent == null
3770 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3771 loge("The calling package is not allowed to access ISD-R.");
3772 throw new SecurityException(
3773 "The calling package is not allowed to access ISD-R.");
3774 }
Derek Tan740e1672017-06-27 14:56:27 -07003775 }
Derek Tan740e1672017-06-27 14:56:27 -07003776
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003777 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08003778 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
3779 null /* workSource */);
3780 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003781 return response;
3782 } finally {
3783 Binder.restoreCallingIdentity(identity);
3784 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003785 }
3786
3787 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003788 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003789 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3790 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08003791 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3792 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
3793 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003794
Jordan Liu4c733742019-02-28 12:03:40 -08003795 @Override
3796 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
3797 enforceModifyPermission();
3798 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
3799 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3800 channel);
3801 }
3802
3803 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003804 final long identity = Binder.clearCallingIdentity();
3805 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003806 if (channel < 0) {
3807 return false;
3808 }
Jordan Liu4c733742019-02-28 12:03:40 -08003809 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
3810 null /* workSource */);
3811 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003812 return success;
3813 } finally {
3814 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003815 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003816 }
3817
3818 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003819 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003820 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003821 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3822 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08003823 if (DBG) {
3824 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3825 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3826 + p3 + " data=" + data);
3827 }
3828 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
3829 command, p1, p2, p3, data);
3830 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003831
Jordan Liu4c733742019-02-28 12:03:40 -08003832 @Override
3833 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
3834 int command, int p1, int p2, int p3, String data) {
3835 enforceModifyPermission();
3836 if (DBG) {
3837 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
3838 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3839 + p3 + " data=" + data);
3840 }
3841 return iccTransmitApduLogicalChannelWithPermission(
3842 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
3843 data);
3844 }
3845
3846 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
3847 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003848 final long identity = Binder.clearCallingIdentity();
3849 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003850 if (channel < 0) {
3851 return "";
3852 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003853
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003854 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08003855 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
3856 null /* workSource */);
3857 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003858
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003859 // Append the returned status code to the end of the response payload.
3860 String s = Integer.toHexString(
3861 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3862 if (response.payload != null) {
3863 s = IccUtils.bytesToHexString(response.payload) + s;
3864 }
3865 return s;
3866 } finally {
3867 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003868 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003869 }
Jake Hambye994d462014-02-03 13:10:13 -08003870
Evan Charltonc66da362014-05-16 14:06:40 -07003871 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003872 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3873 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003874 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3875 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003876 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08003877 if (DBG) {
3878 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3879 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3880 }
3881 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
3882 cla, command, p1, p2, p3, data);
3883 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003884
Jordan Liu4c733742019-02-28 12:03:40 -08003885 @Override
3886 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
3887 int command, int p1, int p2, int p3, String data) {
3888 enforceModifyPermission();
3889 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3890 if (DBG) {
3891 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
3892 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
3893 + " data=" + data);
3894 }
3895
3896 return iccTransmitApduBasicChannelWithPermission(
3897 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
3898 p2, p3, data);
3899 }
3900
3901 // open APDU basic channel assuming the caller has sufficient permissions
3902 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
3903 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003904 final long identity = Binder.clearCallingIdentity();
3905 try {
3906 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3907 && TextUtils.equals(ISDR_AID, data)) {
3908 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003909 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3910 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003911 if (bestComponent == null
3912 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3913 loge("The calling package is not allowed to select ISD-R.");
3914 throw new SecurityException(
3915 "The calling package is not allowed to select ISD-R.");
3916 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003917 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003918
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003919 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08003920 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
3921 null /* workSource */);
3922 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003923
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003924 // Append the returned status code to the end of the response payload.
3925 String s = Integer.toHexString(
3926 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3927 if (response.payload != null) {
3928 s = IccUtils.bytesToHexString(response.payload) + s;
3929 }
3930 return s;
3931 } finally {
3932 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003933 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003934 }
3935
3936 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003937 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003938 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003939 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3940 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003941
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003942 final long identity = Binder.clearCallingIdentity();
3943 try {
3944 if (DBG) {
3945 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3946 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3947 }
3948
3949 IccIoResult response =
3950 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3951 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3952 subId);
3953
3954 if (DBG) {
3955 log("Exchange SIM_IO [R]" + response);
3956 }
3957
3958 byte[] result = null;
3959 int length = 2;
3960 if (response.payload != null) {
3961 length = 2 + response.payload.length;
3962 result = new byte[length];
3963 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3964 } else {
3965 result = new byte[length];
3966 }
3967
3968 result[length - 1] = (byte) response.sw2;
3969 result[length - 2] = (byte) response.sw1;
3970 return result;
3971 } finally {
3972 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003973 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003974 }
3975
Nathan Haroldb3014052017-01-25 15:57:32 -08003976 /**
3977 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3978 * on a particular subscription
3979 */
sqianb6e41952018-03-12 14:54:01 -07003980 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3981 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3982 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3983 return null;
3984 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003985
3986 final long identity = Binder.clearCallingIdentity();
3987 try {
3988 if (appType != TelephonyManager.APPTYPE_USIM
3989 && appType != TelephonyManager.APPTYPE_SIM) {
3990 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3991 return null;
3992 }
3993 Object response = sendRequest(
3994 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3995 if (response instanceof String[]) {
3996 return (String[]) response;
3997 }
3998 // Response is an Exception of some kind,
3999 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004000 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004001 } finally {
4002 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004003 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004004 }
4005
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004006 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004007 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004008 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4009 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004010
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004011 final long identity = Binder.clearCallingIdentity();
4012 try {
4013 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4014 if (response.payload == null) {
4015 return "";
4016 }
Evan Charltonc66da362014-05-16 14:06:40 -07004017
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004018 // Append the returned status code to the end of the response payload.
4019 String s = Integer.toHexString(
4020 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4021 s = IccUtils.bytesToHexString(response.payload) + s;
4022 return s;
4023 } finally {
4024 Binder.restoreCallingIdentity(identity);
4025 }
Evan Charltonc66da362014-05-16 14:06:40 -07004026 }
4027
Jake Hambye994d462014-02-03 13:10:13 -08004028 /**
4029 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4030 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4031 *
4032 * @param itemID the ID of the item to read
4033 * @return the NV item as a String, or null on error.
4034 */
4035 @Override
4036 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004037 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004038 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4039 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004040
4041 final long identity = Binder.clearCallingIdentity();
4042 try {
4043 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004044 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004045 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4046 return value;
4047 } finally {
4048 Binder.restoreCallingIdentity(identity);
4049 }
Jake Hambye994d462014-02-03 13:10:13 -08004050 }
4051
4052 /**
4053 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4054 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4055 *
4056 * @param itemID the ID of the item to read
4057 * @param itemValue the value to write, as a String
4058 * @return true on success; false on any failure
4059 */
4060 @Override
4061 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004062 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004063 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4064 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004065
4066 final long identity = Binder.clearCallingIdentity();
4067 try {
4068 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4069 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004070 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004071 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4072 return success;
4073 } finally {
4074 Binder.restoreCallingIdentity(identity);
4075 }
Jake Hambye994d462014-02-03 13:10:13 -08004076 }
4077
4078 /**
4079 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4080 * Used for device configuration by some CDMA operators.
4081 *
4082 * @param preferredRoamingList byte array containing the new PRL
4083 * @return true on success; false on any failure
4084 */
4085 @Override
4086 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004087 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4088 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004089
4090 final long identity = Binder.clearCallingIdentity();
4091 try {
4092 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4093 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4094 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4095 return success;
4096 } finally {
4097 Binder.restoreCallingIdentity(identity);
4098 }
Jake Hambye994d462014-02-03 13:10:13 -08004099 }
4100
4101 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004102 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004103 * Used for device configuration by some CDMA operators.
4104 *
chen xu6dac5ab2018-10-26 17:39:23 -07004105 * @param slotIndex - device slot.
4106 *
Jake Hambye994d462014-02-03 13:10:13 -08004107 * @return true on success; false on any failure
4108 */
4109 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004110 public boolean resetModemConfig(int slotIndex) {
4111 Phone phone = PhoneFactory.getPhone(slotIndex);
4112 if (phone != null) {
4113 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4114 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004115
chen xu6dac5ab2018-10-26 17:39:23 -07004116 final long identity = Binder.clearCallingIdentity();
4117 try {
4118 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4119 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4120 return success;
4121 } finally {
4122 Binder.restoreCallingIdentity(identity);
4123 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004124 }
chen xu6dac5ab2018-10-26 17:39:23 -07004125 return false;
4126 }
4127
4128 /**
4129 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4130 *
4131 * @param slotIndex - device slot.
4132 *
4133 * @return true on success; false on any failure
4134 */
4135 @Override
4136 public boolean rebootModem(int slotIndex) {
4137 Phone phone = PhoneFactory.getPhone(slotIndex);
4138 if (phone != null) {
4139 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4140 mApp, phone.getSubId(), "rebootModem");
4141
4142 final long identity = Binder.clearCallingIdentity();
4143 try {
4144 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4145 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4146 return success;
4147 } finally {
4148 Binder.restoreCallingIdentity(identity);
4149 }
4150 }
4151 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004152 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004153
Svet Ganovb320e182015-04-16 12:30:10 -07004154 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004155 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004156 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004157 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004158 return new String[0];
4159 }
4160
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004161 final long identity = Binder.clearCallingIdentity();
4162 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004163 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004164 } finally {
4165 Binder.restoreCallingIdentity(identity);
4166 }
Wink Saville36469e72014-06-11 15:17:00 -07004167 }
4168
Brad Ebinger51f743a2017-01-23 13:50:20 -08004169 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004170 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4171 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004172 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004173 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004174 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004175
4176 final long identity = Binder.clearCallingIdentity();
4177 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004178 ImsResolver resolver = PhoneFactory.getImsResolver();
4179 if (resolver == null) {
4180 // may happen if the device does not support IMS.
4181 return;
4182 }
4183 resolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004184 } finally {
4185 Binder.restoreCallingIdentity(identity);
4186 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004187 }
4188
4189 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004190 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4191 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004192 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004193 public void disableIms(int slotId) {
4194 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004195
4196 final long identity = Binder.clearCallingIdentity();
4197 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004198 ImsResolver resolver = PhoneFactory.getImsResolver();
4199 if (resolver == null) {
4200 // may happen if the device does not support IMS.
4201 return;
4202 }
4203 resolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004204 } finally {
4205 Binder.restoreCallingIdentity(identity);
4206 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004207 }
4208
4209 /**
4210 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4211 * feature or {@link null} if the service is not available. If the feature is available, the
4212 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4213 */
4214 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004215 IImsServiceFeatureCallback callback) {
4216 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004217
4218 final long identity = Binder.clearCallingIdentity();
4219 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004220 ImsResolver resolver = PhoneFactory.getImsResolver();
4221 if (resolver == null) {
4222 // may happen if the device does not support IMS.
4223 return null;
4224 }
4225 return resolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004226 } finally {
4227 Binder.restoreCallingIdentity(identity);
4228 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004229 }
4230
4231 /**
4232 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4233 * feature during emergency calling or {@link null} if the service is not available. If the
4234 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4235 * listener for feature updates.
4236 */
4237 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4238 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004239
4240 final long identity = Binder.clearCallingIdentity();
4241 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004242 ImsResolver resolver = PhoneFactory.getImsResolver();
4243 if (resolver == null) {
4244 // may happen if the device does not support IMS.
4245 return null;
4246 }
4247 return resolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004248 } finally {
4249 Binder.restoreCallingIdentity(identity);
4250 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004251 }
4252
Brad Ebinger5f64b052017-12-14 14:26:15 -08004253 /**
4254 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004255 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004256 */
4257 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4258 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004259
4260 final long identity = Binder.clearCallingIdentity();
4261 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004262 ImsResolver resolver = PhoneFactory.getImsResolver();
4263 if (resolver == null) {
4264 // may happen if the device does not support IMS.
4265 return null;
4266 }
4267 return resolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004268 } finally {
4269 Binder.restoreCallingIdentity(identity);
4270 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004271 }
4272
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004273 /**
4274 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004275 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004276 */
4277 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4278 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004279
4280 final long identity = Binder.clearCallingIdentity();
4281 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004282 ImsResolver resolver = PhoneFactory.getImsResolver();
4283 if (resolver == null) {
4284 // may happen if the device does not support IMS.
4285 return null;
4286 }
4287 return resolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004288 } finally {
4289 Binder.restoreCallingIdentity(identity);
4290 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004291 }
4292
Brad Ebinger884c07b2018-02-15 16:17:40 -08004293 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004294 * Sets the ImsService Package Name that Telephony will bind to.
4295 *
4296 * @param slotId the slot ID that the ImsService should bind for.
4297 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4298 * ImsService is the device default ImsService.
4299 * @param packageName The package name of the application that contains the ImsService to bind
4300 * to.
4301 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4302 * @hide
4303 */
4304 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004305 int[] subIds = SubscriptionManager.getSubId(slotId);
4306 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4307 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4308 "setImsService");
4309
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004310 final long identity = Binder.clearCallingIdentity();
4311 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004312 ImsResolver resolver = PhoneFactory.getImsResolver();
4313 if (resolver == null) {
4314 // may happen if the device does not support IMS.
4315 return false;
4316 }
4317 return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService,
4318 packageName);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004319 } finally {
4320 Binder.restoreCallingIdentity(identity);
4321 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004322 }
4323
4324 /**
4325 * Return the ImsService configuration.
4326 *
4327 * @param slotId The slot that the ImsService is associated with.
4328 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4329 * the device default.
4330 * @return the package name of the ImsService configuration.
4331 */
4332 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004333 int[] subIds = SubscriptionManager.getSubId(slotId);
4334 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4335 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4336 "getImsService");
4337
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004338 final long identity = Binder.clearCallingIdentity();
4339 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004340 ImsResolver resolver = PhoneFactory.getImsResolver();
4341 if (resolver == null) {
4342 // may happen if the device does not support IMS.
4343 return "";
4344 }
4345 return resolver.getImsServiceConfiguration(slotId, isCarrierImsService);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004346 } finally {
4347 Binder.restoreCallingIdentity(identity);
4348 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004349 }
4350
Wink Saville36469e72014-06-11 15:17:00 -07004351 public void setImsRegistrationState(boolean registered) {
4352 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004353
4354 final long identity = Binder.clearCallingIdentity();
4355 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004356 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004357 } finally {
4358 Binder.restoreCallingIdentity(identity);
4359 }
Wink Saville36469e72014-06-11 15:17:00 -07004360 }
4361
4362 /**
Stuart Scott54788802015-03-30 13:18:01 -07004363 * Set the network selection mode to automatic.
4364 *
4365 */
4366 @Override
4367 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004368 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4369 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004370
Pengquan Menge92a50d2018-09-21 15:54:48 -07004371 if (!isActiveSubscription(subId)) {
4372 return;
4373 }
4374
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004375 final long identity = Binder.clearCallingIdentity();
4376 try {
4377 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4378 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4379 } finally {
4380 Binder.restoreCallingIdentity(identity);
4381 }
Stuart Scott54788802015-03-30 13:18:01 -07004382 }
4383
Pengquan Mengea84e042018-09-20 14:57:26 -07004384 /**
4385 * Ask the radio to connect to the input network and change selection mode to manual.
4386 *
4387 * @param subId the id of the subscription.
4388 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4389 * the operator to attach to.
4390 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4391 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4392 * normal network selection next time.
4393 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004394 */
4395 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004396 public boolean setNetworkSelectionModeManual(
4397 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004398 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4399 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004400
4401 if (!isActiveSubscription(subId)) {
4402 return false;
4403 }
4404
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004405 final long identity = Binder.clearCallingIdentity();
4406 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004407 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004408 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004409 if (DBG) {
4410 log("setNetworkSelectionModeManual: subId: " + subId
4411 + " operator: " + operatorInfo);
4412 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004413 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4414 } finally {
4415 Binder.restoreCallingIdentity(identity);
4416 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004417 }
4418
4419 /**
4420 * Scans for available networks.
4421 */
4422 @Override
Hall Liuf19c44f2018-11-27 14:38:17 -08004423 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004424 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4425 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004426 LocationAccessPolicy.LocationPermissionResult locationResult =
4427 LocationAccessPolicy.checkLocationPermission(mApp,
4428 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4429 .setCallingPackage(callingPackage)
4430 .setCallingPid(Binder.getCallingPid())
4431 .setCallingUid(Binder.getCallingUid())
4432 .setMethod("getCellNetworkScanResults")
4433 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4434 .build());
4435 switch (locationResult) {
4436 case DENIED_HARD:
4437 throw new SecurityException("Not allowed to access scan results -- location");
4438 case DENIED_SOFT:
4439 return null;
4440 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004441
Pengquan Menga1bb6272018-09-06 09:59:22 -07004442 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004443 try {
4444 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004445 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004446 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004447 } finally {
4448 Binder.restoreCallingIdentity(identity);
4449 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004450 }
4451
4452 /**
yinxub1bed742017-04-17 11:45:04 -07004453 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004454 *
yinxub1bed742017-04-17 11:45:04 -07004455 * @param subId id of the subscription
4456 * @param request contains the radio access networks with bands/channels to scan
4457 * @param messenger callback messenger for scan results or errors
4458 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004459 * @return the id of the requested scan which can be used to stop the scan.
4460 */
4461 @Override
4462 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Hall Liuf19c44f2018-11-27 14:38:17 -08004463 IBinder binder, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004464 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4465 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004466 LocationAccessPolicy.LocationPermissionResult locationResult =
4467 LocationAccessPolicy.checkLocationPermission(mApp,
4468 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4469 .setCallingPackage(callingPackage)
4470 .setCallingPid(Binder.getCallingPid())
4471 .setCallingUid(Binder.getCallingUid())
4472 .setMethod("requestNetworkScan")
4473 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4474 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004475 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
4476 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request);
4477 if (e != null) {
4478 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4479 throw e;
4480 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07004481 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004482 return TelephonyScanManager.INVALID_SCAN_ID;
4483 }
4484 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004485 }
Hall Liu912dfd32019-04-25 14:02:26 -07004486 int callingUid = Binder.getCallingUid();
4487 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07004488 final long identity = Binder.clearCallingIdentity();
4489 try {
4490 return mNetworkScanRequestTracker.startNetworkScan(
4491 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07004492 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07004493 } finally {
4494 Binder.restoreCallingIdentity(identity);
4495 }
yinxu504e1392017-04-12 16:03:22 -07004496 }
4497
Hall Liub2ac8ef2019-02-28 15:56:23 -08004498 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
4499 NetworkScanRequest request) {
4500 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4501 != PERMISSION_GRANTED) {
4502 return new SecurityException("permission.NETWORK_SCAN is needed for network scans"
4503 + " without location access.");
4504 }
4505
4506 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4507 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004508 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4509 return new SecurityException("Specific channels must not be"
4510 + " scanned without location access.");
4511 }
4512 }
4513 }
4514
Hall Liub2ac8ef2019-02-28 15:56:23 -08004515 return null;
4516 }
4517
yinxu504e1392017-04-12 16:03:22 -07004518 /**
4519 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004520 *
4521 * @param subId id of the subscription
4522 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004523 */
4524 @Override
4525 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004526 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4527 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004528
Hall Liu912dfd32019-04-25 14:02:26 -07004529 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004530 final long identity = Binder.clearCallingIdentity();
4531 try {
Hall Liu912dfd32019-04-25 14:02:26 -07004532 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004533 } finally {
4534 Binder.restoreCallingIdentity(identity);
4535 }
yinxu504e1392017-04-12 16:03:22 -07004536 }
4537
4538 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004539 * Get the calculated preferred network type.
4540 * Used for debugging incorrect network type.
4541 *
4542 * @return the preferred network type, defined in RILConstants.java.
4543 */
4544 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004545 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004546 final Phone defaultPhone = getDefaultPhone();
4547 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4548 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004549 return RILConstants.PREFERRED_NETWORK_MODE;
4550 }
4551
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004552 final long identity = Binder.clearCallingIdentity();
4553 try {
4554 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004555 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004556 } finally {
4557 Binder.restoreCallingIdentity(identity);
4558 }
Junda Liu84d15a22014-07-02 11:21:04 -07004559 }
4560
4561 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004562 * Get the preferred network type.
4563 * Used for device configuration by some CDMA operators.
4564 *
4565 * @return the preferred network type, defined in RILConstants.java.
4566 */
4567 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004568 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08004569 TelephonyPermissions
4570 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4571 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004572
4573 final long identity = Binder.clearCallingIdentity();
4574 try {
4575 if (DBG) log("getPreferredNetworkType");
4576 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4577 int networkType = (result != null ? result[0] : -1);
4578 if (DBG) log("getPreferredNetworkType: " + networkType);
4579 return networkType;
4580 } finally {
4581 Binder.restoreCallingIdentity(identity);
4582 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004583 }
4584
4585 /**
4586 * Set the preferred network type.
4587 * Used for device configuration by some CDMA operators.
4588 *
4589 * @param networkType the preferred network type, defined in RILConstants.java.
4590 * @return true on success; false on any failure.
4591 */
4592 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004593 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004594 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4595 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004596
4597 final long identity = Binder.clearCallingIdentity();
4598 try {
4599 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4600 Boolean success = (Boolean) sendRequest(
4601 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4602 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4603 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004604 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004605 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4606 }
4607 return success;
4608 } finally {
4609 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004610 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004611 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004612
4613 /**
Miaoa84611c2019-03-15 09:21:10 +08004614 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004615 *
Miaoa84611c2019-03-15 09:21:10 +08004616 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004617 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004618 * @hide
4619 */
4620 @Override
Miaoa84611c2019-03-15 09:21:10 +08004621 public boolean getTetherApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004622 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004623 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08004624 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004625 try {
Miaoa84611c2019-03-15 09:21:10 +08004626 if (phone != null) {
4627 return phone.hasMatchedTetherApnSetting();
4628 } else {
4629 return false;
4630 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004631 } finally {
4632 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004633 }
Junda Liu475951f2014-11-07 16:45:03 -08004634 }
4635
4636 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004637 * Set mobile data enabled
4638 * Used by the user through settings etc to turn on/off mobile data
4639 *
4640 * @param enable {@code true} turn turn data on, else {@code false}
4641 */
4642 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004643 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004644 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4645 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004646
4647 final long identity = Binder.clearCallingIdentity();
4648 try {
4649 int phoneId = mSubscriptionController.getPhoneId(subId);
4650 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4651 Phone phone = PhoneFactory.getPhone(phoneId);
4652 if (phone != null) {
4653 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08004654 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004655 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004656 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004657 }
4658 } finally {
4659 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004660 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004661 }
4662
4663 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004664 * Get the user enabled state of Mobile Data.
4665 *
4666 * TODO: remove and use isUserDataEnabled.
4667 * This can't be removed now because some vendor codes
4668 * calls through ITelephony directly while they should
4669 * use TelephonyManager.
4670 *
4671 * @return true on enabled
4672 */
4673 @Override
4674 public boolean getDataEnabled(int subId) {
4675 return isUserDataEnabled(subId);
4676 }
4677
4678 /**
4679 * Get whether mobile data is enabled per user setting.
4680 *
4681 * There are other factors deciding whether mobile data is actually enabled, but they are
4682 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004683 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004684 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004685 *
4686 * @return {@code true} if data is enabled else {@code false}
4687 */
4688 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004689 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004690 try {
4691 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4692 null);
4693 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004694 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4695 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004696 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004697
4698 final long identity = Binder.clearCallingIdentity();
4699 try {
4700 int phoneId = mSubscriptionController.getPhoneId(subId);
4701 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4702 Phone phone = PhoneFactory.getPhone(phoneId);
4703 if (phone != null) {
4704 boolean retVal = phone.isUserDataEnabled();
4705 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4706 return retVal;
4707 } else {
4708 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4709 return false;
4710 }
4711 } finally {
4712 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004713 }
4714 }
4715
4716 /**
4717 * Get whether mobile data is enabled.
4718 *
4719 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4720 * whether mobile data is actually enabled.
4721 *
4722 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4723 *
4724 * @return {@code true} if data is enabled else {@code false}
4725 */
4726 @Override
4727 public boolean isDataEnabled(int subId) {
4728 try {
4729 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4730 null);
4731 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004732 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4733 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004734 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004735
4736 final long identity = Binder.clearCallingIdentity();
4737 try {
4738 int phoneId = mSubscriptionController.getPhoneId(subId);
4739 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4740 Phone phone = PhoneFactory.getPhone(phoneId);
4741 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08004742 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004743 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4744 return retVal;
4745 } else {
4746 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4747 return false;
4748 }
4749 } finally {
4750 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004751 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004752 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004753
4754 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004755 public int getCarrierPrivilegeStatus(int subId) {
4756 final Phone phone = getPhone(subId);
4757 if (phone == null) {
4758 loge("getCarrierPrivilegeStatus: Invalid subId");
4759 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4760 }
4761 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004762 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004763 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004764 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4765 }
4766 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004767 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004768 }
Junda Liu29340342014-07-10 15:23:27 -07004769
4770 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004771 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4772 final Phone phone = getPhone(subId);
4773 if (phone == null) {
4774 loge("getCarrierPrivilegeStatus: Invalid subId");
4775 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4776 }
4777 UiccProfile profile =
4778 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4779 if (profile == null) {
4780 loge("getCarrierPrivilegeStatus: No UICC");
4781 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4782 }
4783 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4784 }
4785
4786 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07004787 public int checkCarrierPrivilegesForPackage(String pkgName) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004788 final Phone defaultPhone = getDefaultPhone();
Junda Liu317d70b2016-03-08 09:33:53 -08004789 if (TextUtils.isEmpty(pkgName))
4790 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004791 UiccCard card = UiccController.getInstance().getUiccCard(defaultPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004792 if (card == null) {
4793 loge("checkCarrierPrivilegesForPackage: No UICC");
4794 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4795 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004796 return card.getCarrierPrivilegeStatus(defaultPhone.getContext().getPackageManager(),
4797 pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004798 }
4799
4800 @Override
4801 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004802 if (TextUtils.isEmpty(pkgName))
4803 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004804 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4805 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4806 UiccCard card = UiccController.getInstance().getUiccCard(i);
4807 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004808 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004809 continue;
4810 }
4811
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004812 result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004813 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4814 break;
4815 }
4816 }
4817
4818 return result;
Junda Liu29340342014-07-10 15:23:27 -07004819 }
Derek Tan89e89d42014-07-08 17:00:10 -07004820
4821 @Override
Junda Liue64de782015-04-16 17:19:16 -07004822 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4823 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4824 loge("phoneId " + phoneId + " is not valid.");
4825 return null;
4826 }
4827 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004828 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004829 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004830 return null ;
4831 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004832 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004833 }
4834
Amith Yamasani6e118872016-02-19 12:53:51 -08004835 @Override
4836 public List<String> getPackagesWithCarrierPrivileges() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004837 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08004838 List<String> privilegedPackages = new ArrayList<>();
4839 List<PackageInfo> packages = null;
4840 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4841 UiccCard card = UiccController.getInstance().getUiccCard(i);
4842 if (card == null) {
4843 // No UICC in that slot.
4844 continue;
4845 }
4846 if (card.hasCarrierPrivilegeRules()) {
4847 if (packages == null) {
4848 // Only check packages in user 0 for now
4849 packages = pm.getInstalledPackagesAsUser(
4850 PackageManager.MATCH_DISABLED_COMPONENTS
4851 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4852 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
4853 }
4854 for (int p = packages.size() - 1; p >= 0; p--) {
4855 PackageInfo pkgInfo = packages.get(p);
4856 if (pkgInfo != null && pkgInfo.packageName != null
4857 && card.getCarrierPrivilegeStatus(pkgInfo)
4858 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4859 privilegedPackages.add(pkgInfo.packageName);
4860 }
4861 }
4862 }
4863 }
4864 return privilegedPackages;
4865 }
4866
Wink Savilleb564aae2014-10-23 10:18:09 -07004867 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004868 final Phone phone = getPhone(subId);
4869 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004870 if (card == null) {
4871 loge("getIccId: No UICC");
4872 return null;
4873 }
4874 String iccId = card.getIccId();
4875 if (TextUtils.isEmpty(iccId)) {
4876 loge("getIccId: ICC ID is null or empty.");
4877 return null;
4878 }
4879 return iccId;
4880 }
4881
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004882 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004883 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4884 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004885 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4886 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004887
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004888 final long identity = Binder.clearCallingIdentity();
4889 try {
4890 final String iccId = getIccId(subId);
4891 final Phone phone = getPhone(subId);
4892 if (phone == null) {
4893 return false;
4894 }
4895 final String subscriberId = phone.getSubscriberId();
4896
4897 if (DBG_MERGE) {
4898 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4899 + subscriberId + " to " + number);
4900 }
4901
4902 if (TextUtils.isEmpty(iccId)) {
4903 return false;
4904 }
4905
4906 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4907
4908 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4909 if (alphaTag == null) {
4910 editor.remove(alphaTagPrefKey);
4911 } else {
4912 editor.putString(alphaTagPrefKey, alphaTag);
4913 }
4914
4915 // Record both the line number and IMSI for this ICCID, since we need to
4916 // track all merged IMSIs based on line number
4917 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4918 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4919 if (number == null) {
4920 editor.remove(numberPrefKey);
4921 editor.remove(subscriberPrefKey);
4922 } else {
4923 editor.putString(numberPrefKey, number);
4924 editor.putString(subscriberPrefKey, subscriberId);
4925 }
4926
4927 editor.commit();
4928 return true;
4929 } finally {
4930 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004931 }
Derek Tan7226c842014-07-02 17:42:23 -07004932 }
4933
4934 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004935 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004936 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004937 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004938 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004939 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004940 return null;
4941 }
Derek Tan97ebb422014-09-05 16:55:38 -07004942
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004943 final long identity = Binder.clearCallingIdentity();
4944 try {
4945 String iccId = getIccId(subId);
4946 if (iccId != null) {
4947 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4948 if (DBG_MERGE) {
4949 log("getLine1NumberForDisplay returning "
4950 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4951 }
4952 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004953 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004954 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4955 return null;
4956 } finally {
4957 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004958 }
Derek Tan7226c842014-07-02 17:42:23 -07004959 }
4960
4961 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004962 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004963 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004964 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004965 return null;
4966 }
Derek Tan97ebb422014-09-05 16:55:38 -07004967
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004968 final long identity = Binder.clearCallingIdentity();
4969 try {
4970 String iccId = getIccId(subId);
4971 if (iccId != null) {
4972 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4973 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4974 }
4975 return null;
4976 } finally {
4977 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004978 }
Derek Tan7226c842014-07-02 17:42:23 -07004979 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004980
4981 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004982 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004983 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4984 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004985 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004986 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4987 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004988 return null;
4989 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004990
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004991 final long identity = Binder.clearCallingIdentity();
4992 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004993 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004994 final TelephonyManager tele = TelephonyManager.from(context);
4995 final SubscriptionManager sub = SubscriptionManager.from(context);
4996
4997 // Figure out what subscribers are currently active
4998 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
4999 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5000 // the process, where TelephonyManager was instantiated.
5001 // Otherwise AppOps check will fail.
5002
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005003 final int[] subIds = sub.getActiveSubscriptionIdList();
5004 for (int subId : subIds) {
5005 activeSubscriberIds.add(tele.getSubscriberId(subId));
5006 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005007
5008 // First pass, find a number override for an active subscriber
5009 String mergeNumber = null;
5010 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5011 for (String key : prefs.keySet()) {
5012 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5013 final String subscriberId = (String) prefs.get(key);
5014 if (activeSubscriberIds.contains(subscriberId)) {
5015 final String iccId = key.substring(
5016 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5017 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5018 mergeNumber = (String) prefs.get(numberKey);
5019 if (DBG_MERGE) {
5020 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5021 + " for active subscriber " + subscriberId);
5022 }
5023 if (!TextUtils.isEmpty(mergeNumber)) {
5024 break;
5025 }
5026 }
5027 }
5028 }
5029
5030 // Shortcut when no active merged subscribers
5031 if (TextUtils.isEmpty(mergeNumber)) {
5032 return null;
5033 }
5034
5035 // Second pass, find all subscribers under that line override
5036 final ArraySet<String> result = new ArraySet<>();
5037 for (String key : prefs.keySet()) {
5038 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5039 final String number = (String) prefs.get(key);
5040 if (mergeNumber.equals(number)) {
5041 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5042 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5043 final String subscriberId = (String) prefs.get(subscriberKey);
5044 if (!TextUtils.isEmpty(subscriberId)) {
5045 result.add(subscriberId);
5046 }
5047 }
5048 }
5049 }
5050
5051 final String[] resultArray = result.toArray(new String[result.size()]);
5052 Arrays.sort(resultArray);
5053 if (DBG_MERGE) {
5054 Slog.d(LOG_TAG,
5055 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5056 }
5057 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005058 } finally {
5059 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005060 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005061 }
5062
5063 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005064 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005065 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5066 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005067
5068 final long identity = Binder.clearCallingIdentity();
5069 try {
5070 final Phone phone = getPhone(subId);
5071 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5072 } finally {
5073 Binder.restoreCallingIdentity(identity);
5074 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005075 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005076
5077 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005078 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005079 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5080 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005081 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005082
5083 final long identity = Binder.clearCallingIdentity();
5084 try {
5085 final Phone phone = getPhone(subId);
5086 if (phone == null) {
5087 return false;
5088 }
5089 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5090 cdmaNonRoamingList);
5091 } finally {
5092 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005093 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005094 }
5095
5096 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005097 @Deprecated
5098 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5099 enforceModifyPermission();
5100
5101 int returnValue = 0;
5102 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005103 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005104 if(result.exception == null) {
5105 if (result.result != null) {
5106 byte[] responseData = (byte[])(result.result);
5107 if(responseData.length > oemResp.length) {
5108 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5109 responseData.length + "bytes. Buffer Size is " +
5110 oemResp.length + "bytes.");
5111 }
5112 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5113 returnValue = responseData.length;
5114 }
5115 } else {
5116 CommandException ex = (CommandException) result.exception;
5117 returnValue = ex.getCommandError().ordinal();
5118 if(returnValue > 0) returnValue *= -1;
5119 }
5120 } catch (RuntimeException e) {
5121 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5122 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5123 if(returnValue > 0) returnValue *= -1;
5124 }
5125
5126 return returnValue;
5127 }
5128
5129 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005130 public void setRadioCapability(RadioAccessFamily[] rafs) {
5131 try {
5132 ProxyController.getInstance().setRadioCapability(rafs);
5133 } catch (RuntimeException e) {
5134 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5135 }
5136 }
5137
5138 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005139 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005140 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005141 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005142 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005143 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005144 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005145 final long identity = Binder.clearCallingIdentity();
5146 try {
chen xub97461a2018-10-26 14:17:57 -07005147 TelephonyPermissions
5148 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5149 mApp, phone.getSubId(), "getRadioAccessFamily");
5150 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005151 } finally {
5152 Binder.restoreCallingIdentity(identity);
5153 }
chen xub97461a2018-10-26 14:17:57 -07005154 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005155 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005156
5157 @Override
5158 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005159 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005160 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005161
5162 final long identity = Binder.clearCallingIdentity();
5163 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005164 ImsManager.getInstance(defaultPhone.getContext(),
5165 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005166 } finally {
5167 Binder.restoreCallingIdentity(identity);
5168 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005169 }
5170
5171 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005172 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005173 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00005174 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005175 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005176 return false;
5177 }
Svet Ganovb320e182015-04-16 12:30:10 -07005178
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005179 final long identity = Binder.clearCallingIdentity();
5180 try {
5181 // Check the user preference and the system-level IMS setting. Even if the user has
5182 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5183 // In the long run, we may instead need to check if there exists a connection service
5184 // which can support video calling.
5185 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005186 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005187 return imsManager.isVtEnabledByPlatform()
5188 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5189 && imsManager.isVtEnabledByUser();
5190 } finally {
5191 Binder.restoreCallingIdentity(identity);
5192 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005193 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005194
Andrew Leea1239f22015-03-02 17:44:07 -08005195 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005196 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
5197 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5198 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5199 return false;
5200 }
5201
5202 final long identity = Binder.clearCallingIdentity();
5203 try {
5204 CarrierConfigManager configManager =
5205 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005206 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005207 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5208 } finally {
5209 Binder.restoreCallingIdentity(identity);
5210 }
Andrew Leea1239f22015-03-02 17:44:07 -08005211 }
5212
5213 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005214 public boolean isWorldPhone(int subId, String callingPackage) {
5215 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5216 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5217 return false;
5218 }
5219
5220 final long identity = Binder.clearCallingIdentity();
5221 try {
5222 CarrierConfigManager configManager =
5223 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005224 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005225 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5226 } finally {
5227 Binder.restoreCallingIdentity(identity);
5228 }
Andrew Leea1239f22015-03-02 17:44:07 -08005229 }
5230
Andrew Lee9431b832015-03-09 18:46:45 -07005231 @Override
5232 public boolean isTtyModeSupported() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005233 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005234 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005235 }
5236
5237 @Override
5238 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005239 final long identity = Binder.clearCallingIdentity();
5240 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005241 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005242 } finally {
5243 Binder.restoreCallingIdentity(identity);
5244 }
Andrew Lee9431b832015-03-09 18:46:45 -07005245 }
5246
Hall Liuf6668912018-10-31 17:05:23 -07005247 /**
5248 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5249 * support for the feature and device firmware support.
5250 *
5251 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5252 */
5253 @Override
5254 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005255 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005256 final Phone phone = getPhone(subscriptionId);
5257 if (phone == null) {
5258 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5259 return false;
5260 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005261 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005262 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005263 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5264 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005265 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005266 return isCarrierSupported && isDeviceSupported;
5267 } finally {
5268 Binder.restoreCallingIdentity(identity);
5269 }
Hall Liu98187582018-01-22 19:15:32 -08005270 }
5271
Hall Liuf6668912018-10-31 17:05:23 -07005272 /**
5273 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
5274 * both also support RTT.
5275 */
5276 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005277 final long identity = Binder.clearCallingIdentity();
5278 try {
Hall Liuf6668912018-10-31 17:05:23 -07005279 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005280 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005281 } finally {
5282 Binder.restoreCallingIdentity(identity);
5283 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005284 }
5285
Sanket Padawe7310cc72015-01-14 09:53:20 -08005286 /**
5287 * Returns the unique device ID of phone, for example, the IMEI for
5288 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5289 *
5290 * <p>Requires Permission:
5291 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5292 */
5293 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005294 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005295 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005296 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005297 return null;
5298 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005299 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005300 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
5301 callingPackage, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005302 return null;
5303 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005304
5305 final long identity = Binder.clearCallingIdentity();
5306 try {
5307 return phone.getDeviceId();
5308 } finally {
5309 Binder.restoreCallingIdentity(identity);
5310 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005311 }
5312
Ping Sunc67b7c22016-03-02 19:16:45 +08005313 /**
5314 * {@hide}
5315 * Returns the IMS Registration Status on a particular subid
5316 *
5317 * @param subId
5318 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005319 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005320 Phone phone = getPhone(subId);
5321 if (phone != null) {
5322 return phone.isImsRegistered();
5323 } else {
5324 return false;
5325 }
5326 }
5327
Santos Cordon7a1885b2015-02-03 11:15:19 -08005328 @Override
5329 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005330 final long identity = Binder.clearCallingIdentity();
5331 try {
5332 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5333 } finally {
5334 Binder.restoreCallingIdentity(identity);
5335 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005336 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005337
Tyler Gunnf70ed162019-04-03 15:28:53 -07005338 @Override
5339 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5340 final long identity = Binder.clearCallingIdentity();
5341 try {
5342 Phone phone = getPhone(subscriptionId);
5343 if (phone == null) {
5344 return null;
5345 }
5346 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5347 } finally {
5348 Binder.restoreCallingIdentity(identity);
5349 }
5350 }
5351
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005352 /**
5353 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005354 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005355 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005356 final long identity = Binder.clearCallingIdentity();
5357 try {
5358 Phone phone = getPhone(subId);
5359 if (phone != null) {
5360 return phone.isWifiCallingEnabled();
5361 } else {
5362 return false;
5363 }
5364 } finally {
5365 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005366 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005367 }
5368
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005369 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005370 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005371 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005372 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005373 final long identity = Binder.clearCallingIdentity();
5374 try {
5375 Phone phone = getPhone(subId);
5376 if (phone != null) {
5377 return phone.isVideoEnabled();
5378 } else {
5379 return false;
5380 }
5381 } finally {
5382 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005383 }
5384 }
5385
5386 /**
5387 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5388 * defined in {@link ImsRegistrationImplBase}.
5389 */
5390 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005391 final long identity = Binder.clearCallingIdentity();
5392 try {
5393 Phone phone = getPhone(subId);
5394 if (phone != null) {
5395 return phone.getImsRegistrationTech();
5396 } else {
5397 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5398 }
5399 } finally {
5400 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005401 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005402 }
5403
Stuart Scott8eef64f2015-04-08 15:13:54 -07005404 @Override
5405 public void factoryReset(int subId) {
5406 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005407 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5408 return;
5409 }
5410
Svet Ganovcc087f82015-05-12 20:35:54 -07005411 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005412
Svet Ganovcc087f82015-05-12 20:35:54 -07005413 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005414 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5415 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005416 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005417 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005418 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005419 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5420 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005421 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005422 // There has been issues when Sms raw table somehow stores orphan
5423 // fragments. They lead to garbled message when new fragments come
5424 // in and combined with those stale ones. In case this happens again,
5425 // user can reset all network settings which will clean up this table.
5426 cleanUpSmsRawTable(getDefaultPhone().getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07005427 } finally {
5428 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005429 }
5430 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005431
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005432 private void cleanUpSmsRawTable(Context context) {
5433 ContentResolver resolver = context.getContentResolver();
5434 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5435 resolver.delete(uri, null, null);
5436 }
5437
Narayan Kamath1c496c22015-04-16 14:40:19 +01005438 @Override
chen xu5d3637b2019-01-21 23:31:38 -08005439 public String getSimLocaleForSubscriber(int subId) {
5440 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5441 final Phone phone = getPhone(subId);
5442 if (phone == null) {
5443 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08005444 return null;
chen xu5d3637b2019-01-21 23:31:38 -08005445 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005446 final long identity = Binder.clearCallingIdentity();
5447 try {
chen xu5d3637b2019-01-21 23:31:38 -08005448 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5449 phone.getContext().getOpPackageName());
chen xu6291c472019-02-04 12:55:53 -08005450 if (info == null) {
5451 log("getSimLocaleForSubscriber, inactive subId: " + subId);
5452 return null;
5453 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005454 // Try and fetch the locale from the carrier properties or from the SIM language
5455 // preferences (EF-PL and EF-LI)...
5456 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005457 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08005458 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5459 if (localeFromDefaultSim != null) {
5460 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5461 if (DBG) log("Using locale from subId: " + subId + " locale: "
5462 + localeFromDefaultSim);
5463 return localeFromDefaultSim.toLanguageTag();
5464 } else {
5465 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005466 }
5467 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005468
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005469 // The SIM language preferences only store a language (e.g. fr = French), not an
5470 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5471 // the SIM and carrier preferences does not include a country we add the country
5472 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005473 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005474 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08005475 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005476 return mccLocale.toLanguageTag();
5477 }
5478
5479 if (DBG) log("No locale found - returning null");
5480 return null;
5481 } finally {
5482 Binder.restoreCallingIdentity(identity);
5483 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005484 }
5485
5486 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005487 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005488 }
5489
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005490 /**
5491 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5492 */
5493 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005494 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005495 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005496
Chenjie Yu1ba97252018-01-11 18:16:20 -08005497 private final ModemActivityInfo mLastModemActivityInfo =
5498 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
5499
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005500 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005501 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5502 * representing the state of the modem.
5503 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005504 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5505 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005506 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005507 */
5508 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005509 public void requestModemActivityInfo(ResultReceiver result) {
5510 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005511 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005512
5513 final long identity = Binder.clearCallingIdentity();
5514 try {
5515 ModemActivityInfo ret = null;
5516 synchronized (mLastModemActivityInfo) {
5517 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5518 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07005519 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07005520 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005521 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
5522 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005523 mergedTxTimeMs[i] = info.getTxTimeMillis()[i]
5524 + mLastModemActivityInfo.getTxTimeMillis()[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005525 }
5526 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005527 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
5528 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005529 mLastModemActivityInfo.setIdleTimeMillis(
5530 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
5531 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
5532 mLastModemActivityInfo.setRxTimeMillis(
5533 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
5534 mLastModemActivityInfo.setEnergyUsed(
5535 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005536 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005537 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
5538 mLastModemActivityInfo.getSleepTimeMillis(),
5539 mLastModemActivityInfo.getIdleTimeMillis(),
5540 mLastModemActivityInfo.getTxTimeMillis(),
5541 mLastModemActivityInfo.getRxTimeMillis(),
5542 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005543 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005544 Bundle bundle = new Bundle();
5545 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
5546 result.send(0, bundle);
5547 } finally {
5548 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005549 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005550 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005551
Siddharth Rayb8114062018-06-17 15:02:38 -07005552 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
5553 // less than total activity duration.
5554 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
5555 if (info == null) {
5556 return false;
5557 }
5558 int activityDurationMs =
5559 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
5560 int totalTxTimeMs = 0;
5561 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
5562 totalTxTimeMs += info.getTxTimeMillis()[i];
5563 }
5564 return (info.isValid()
5565 && (info.getSleepTimeMillis() <= activityDurationMs)
5566 && (info.getIdleTimeMillis() <= activityDurationMs)
5567 && (info.getRxTimeMillis() <= activityDurationMs)
5568 && (totalTxTimeMs <= activityDurationMs));
5569 }
5570
Jack Yu85bd38a2015-11-09 11:34:32 -08005571 /**
5572 * {@hide}
5573 * Returns the service state information on specified subscription.
5574 */
5575 @Override
5576 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005577 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005578 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08005579 return null;
5580 }
5581
Hall Liuf19c44f2018-11-27 14:38:17 -08005582 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
5583 LocationAccessPolicy.checkLocationPermission(mApp,
5584 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5585 .setCallingPackage(callingPackage)
5586 .setCallingPid(Binder.getCallingPid())
5587 .setCallingUid(Binder.getCallingUid())
5588 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07005589 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005590 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5591 .build());
5592
5593 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
5594 LocationAccessPolicy.checkLocationPermission(mApp,
5595 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5596 .setCallingPackage(callingPackage)
5597 .setCallingPid(Binder.getCallingPid())
5598 .setCallingUid(Binder.getCallingUid())
5599 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07005600 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005601 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5602 .build());
5603 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
5604 boolean hasFinePermission =
5605 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5606 boolean hasCoarsePermission =
5607 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5608
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005609 final long identity = Binder.clearCallingIdentity();
5610 try {
5611 final Phone phone = getPhone(subId);
5612 if (phone == null) {
5613 return null;
5614 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005615
Hall Liuf19c44f2018-11-27 14:38:17 -08005616 ServiceState ss = phone.getServiceState();
5617
5618 // Scrub out the location info in ServiceState depending on what level of access
5619 // the caller has.
5620 if (hasFinePermission) return ss;
5621 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
5622 return ss.sanitizeLocationInfo(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005623 } finally {
5624 Binder.restoreCallingIdentity(identity);
5625 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005626 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005627
5628 /**
5629 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
5630 *
5631 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5632 * voicemail ringtone.
5633 * @return The URI for the ringtone to play when receiving a voicemail from a specific
5634 * PhoneAccount.
5635 */
5636 @Override
5637 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005638 final long identity = Binder.clearCallingIdentity();
5639 try {
5640 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5641 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005642 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005643 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005644
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005645 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
5646 } finally {
5647 Binder.restoreCallingIdentity(identity);
5648 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005649 }
5650
5651 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005652 * Sets the per-account voicemail ringtone.
5653 *
5654 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5655 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5656 *
5657 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5658 * voicemail ringtone.
5659 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5660 * PhoneAccount.
5661 */
5662 @Override
5663 public void setVoicemailRingtoneUri(String callingPackage,
5664 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005665 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005666 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5667 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005668 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005669 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5670 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5671 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005672 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005673
5674 final long identity = Binder.clearCallingIdentity();
5675 try {
5676 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5677 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005678 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005679 }
5680 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5681 } finally {
5682 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005683 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005684 }
5685
5686 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005687 * Returns whether vibration is set for voicemail notification in Phone settings.
5688 *
5689 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5690 * voicemail vibration setting.
5691 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5692 */
5693 @Override
5694 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005695 final long identity = Binder.clearCallingIdentity();
5696 try {
5697 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5698 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005699 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005700 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005701
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005702 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5703 } finally {
5704 Binder.restoreCallingIdentity(identity);
5705 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005706 }
5707
Youhan Wange64578a2016-05-02 15:32:42 -07005708 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005709 * Sets the per-account voicemail vibration.
5710 *
5711 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5712 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5713 *
5714 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5715 * voicemail vibration setting.
5716 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5717 * specific PhoneAccount.
5718 */
5719 @Override
5720 public void setVoicemailVibrationEnabled(String callingPackage,
5721 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005722 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005723 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5724 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005725 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005726 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5727 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5728 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005729 }
5730
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005731 final long identity = Binder.clearCallingIdentity();
5732 try {
5733 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5734 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005735 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005736 }
5737 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5738 } finally {
5739 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005740 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005741 }
5742
5743 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005744 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5745 *
5746 * @throws SecurityException if the caller does not have the required permission
5747 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005748 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005749 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07005750 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005751 }
5752
5753 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005754 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5755 * permission.
5756 *
5757 * @throws SecurityException if the caller does not have the required permission
5758 */
5759 private void enforceSendSmsPermission() {
5760 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5761 }
5762
5763 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005764 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005765 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005766 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005767 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005768 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005769 final long identity = Binder.clearCallingIdentity();
5770 try {
5771 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005772 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005773 if (componentName == null) {
5774 throw new SecurityException(
5775 "Caller not current active visual voicemail package[null]");
5776 }
5777 String vvmPackage = componentName.getPackageName();
5778 if (!callingPackage.equals(vvmPackage)) {
5779 throw new SecurityException("Caller not current active visual voicemail package["
5780 + vvmPackage + "]");
5781 }
5782 } finally {
5783 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005784 }
5785 }
5786
5787 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005788 * Return the application ID for the app type.
5789 *
5790 * @param subId the subscription ID that this request applies to.
5791 * @param appType the uicc app type.
5792 * @return Application ID for specificied app type, or null if no uicc.
5793 */
5794 @Override
5795 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005796 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005797 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005798
5799 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005800 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005801 if (phone == null) {
5802 return null;
5803 }
5804 String aid = null;
5805 try {
5806 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5807 .getApplicationByType(appType).getAid();
5808 } catch (Exception e) {
5809 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5810 }
5811 return aid;
5812 } finally {
5813 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005814 }
Youhan Wange64578a2016-05-02 15:32:42 -07005815 }
5816
Youhan Wang4001d252016-05-11 10:29:41 -07005817 /**
5818 * Return the Electronic Serial Number.
5819 *
5820 * @param subId the subscription ID that this request applies to.
5821 * @return ESN or null if error.
5822 */
5823 @Override
5824 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005825 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005826 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005827
5828 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005829 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005830 if (phone == null) {
5831 return null;
5832 }
5833 String esn = null;
5834 try {
5835 esn = phone.getEsn();
5836 } catch (Exception e) {
5837 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5838 }
5839 return esn;
5840 } finally {
5841 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005842 }
Youhan Wang4001d252016-05-11 10:29:41 -07005843 }
5844
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005845 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005846 * Return the Preferred Roaming List Version.
5847 *
5848 * @param subId the subscription ID that this request applies to.
5849 * @return PRLVersion or null if error.
5850 */
5851 @Override
5852 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005853 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005854 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005855
5856 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005857 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005858 if (phone == null) {
5859 return null;
5860 }
5861 String cdmaPrlVersion = null;
5862 try {
5863 cdmaPrlVersion = phone.getCdmaPrlVersion();
5864 } catch (Exception e) {
5865 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5866 }
5867 return cdmaPrlVersion;
5868 } finally {
5869 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005870 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005871 }
5872
5873 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005874 * Get snapshot of Telephony histograms
5875 * @return List of Telephony histograms
5876 * @hide
5877 */
5878 @Override
5879 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005880 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5881 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005882
5883 final long identity = Binder.clearCallingIdentity();
5884 try {
5885 return RIL.getTelephonyRILTimingHistograms();
5886 } finally {
5887 Binder.restoreCallingIdentity(identity);
5888 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005889 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005890
5891 /**
5892 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08005893 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
5894 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005895 * Require system privileges. In the future we may add this to carrier APIs.
5896 *
Michele Berionne482f8202018-11-27 18:57:59 -08005897 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005898 */
5899 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08005900 @TelephonyManager.SetCarrierRestrictionResult
5901 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005902 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005903 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005904
Michele Berionne482f8202018-11-27 18:57:59 -08005905 if (carrierRestrictionRules == null) {
5906 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08005907 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005908
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005909 final long identity = Binder.clearCallingIdentity();
5910 try {
Michele Berionne482f8202018-11-27 18:57:59 -08005911 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07005912 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005913 } finally {
5914 Binder.restoreCallingIdentity(identity);
5915 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005916 }
5917
5918 /**
5919 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08005920 * Get the allowed carrier list and the excluded carrier list, including the priority between
5921 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005922 * Require system privileges. In the future we may add this to carrier APIs.
5923 *
Michele Berionne482f8202018-11-27 18:57:59 -08005924 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07005925 */
5926 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08005927 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005928 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07005929 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005930
5931 final long identity = Binder.clearCallingIdentity();
5932 try {
Michele Berionne482f8202018-11-27 18:57:59 -08005933 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
5934 if (response instanceof CarrierRestrictionRules) {
5935 return (CarrierRestrictionRules) response;
5936 }
5937 // Response is an Exception of some kind,
5938 // which is signalled to the user as a NULL retval
5939 return null;
5940 } catch (Exception e) {
5941 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
5942 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005943 } finally {
5944 Binder.restoreCallingIdentity(identity);
5945 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005946 }
5947
fionaxu59545b42016-05-25 15:53:37 -07005948 /**
5949 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5950 * @param subId the subscription ID that this action applies to.
5951 * @param enabled control enable or disable metered apns.
5952 * {@hide}
5953 */
5954 @Override
5955 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5956 enforceModifyPermission();
5957 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005958
5959 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005960 if (phone == null) {
5961 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5962 return;
5963 }
5964 try {
5965 phone.carrierActionSetMeteredApnsEnabled(enabled);
5966 } catch (Exception e) {
5967 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005968 } finally {
5969 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005970 }
5971 }
5972
5973 /**
5974 * Action set from carrier signalling broadcast receivers to enable/disable radio
5975 * @param subId the subscription ID that this action applies to.
5976 * @param enabled control enable or disable radio.
5977 * {@hide}
5978 */
5979 @Override
5980 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5981 enforceModifyPermission();
5982 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005983
5984 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005985 if (phone == null) {
5986 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5987 return;
5988 }
5989 try {
5990 phone.carrierActionSetRadioEnabled(enabled);
5991 } catch (Exception e) {
5992 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005993 } finally {
5994 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005995 }
5996 }
5997
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005998 /**
fionaxu8da9cb12017-05-23 15:02:46 -07005999 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6000 * network status based on which carrier apps could apply actions accordingly,
6001 * enable/disable default url handler for example.
6002 *
6003 * @param subId the subscription ID that this action applies to.
6004 * @param report control start/stop reporting the default network status.
6005 * {@hide}
6006 */
6007 @Override
6008 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6009 enforceModifyPermission();
6010 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006011
6012 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006013 if (phone == null) {
6014 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6015 return;
6016 }
6017 try {
6018 phone.carrierActionReportDefaultNetworkStatus(report);
6019 } catch (Exception e) {
6020 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006021 } finally {
6022 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006023 }
6024 }
6025
6026 /**
fionaxud9622282017-07-17 17:51:30 -07006027 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6028 * @param subId the subscription ID that this action applies to.
6029 * {@hide}
6030 */
6031 @Override
6032 public void carrierActionResetAll(int subId) {
6033 enforceModifyPermission();
6034 final Phone phone = getPhone(subId);
6035 if (phone == null) {
6036 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6037 return;
6038 }
6039 try {
6040 phone.carrierActionResetAll();
6041 } catch (Exception e) {
6042 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6043 }
6044 }
6045
6046 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006047 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6048 * bug report is being generated.
6049 */
6050 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006051 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006052 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6053 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006054 writer.println("Permission Denial: can't dump Phone from pid="
6055 + Binder.getCallingPid()
6056 + ", uid=" + Binder.getCallingUid()
6057 + "without permission "
6058 + android.Manifest.permission.DUMP);
6059 return;
6060 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006061 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006062 }
Jack Yueb89b242016-06-22 13:27:47 -07006063
Brad Ebingerdac2f002018-04-03 15:17:52 -07006064 @Override
6065 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6066 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6067 throws RemoteException {
6068 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
6069 }
6070
Jack Yueb89b242016-06-22 13:27:47 -07006071 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006072 * Get aggregated video call data usage since boot.
6073 *
6074 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6075 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006076 * {@hide}
6077 */
6078 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006079 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006080 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6081 null);
6082
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006083 final long identity = Binder.clearCallingIdentity();
6084 try {
6085 // NetworkStatsService keeps tracking the active network interface and identity. It
6086 // records the delta with the corresponding network identity.
6087 // We just return the total video call data usage snapshot since boot.
6088 Phone phone = getPhone(subId);
6089 if (phone != null) {
6090 return phone.getVtDataUsage(perUidStats);
6091 }
6092 return null;
6093 } finally {
6094 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006095 }
Jack Yueb89b242016-06-22 13:27:47 -07006096 }
Jack Yu75ab2952016-07-08 14:29:33 -07006097
6098 /**
6099 * Policy control of data connection. Usually used when data limit is passed.
6100 * @param enabled True if enabling the data, otherwise disabling.
6101 * @param subId Subscription index
6102 * {@hide}
6103 */
6104 @Override
6105 public void setPolicyDataEnabled(boolean enabled, int subId) {
6106 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006107
6108 final long identity = Binder.clearCallingIdentity();
6109 try {
6110 Phone phone = getPhone(subId);
6111 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006112 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006113 }
6114 } finally {
6115 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006116 }
6117 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006118
6119 /**
6120 * Get Client request stats
6121 * @return List of Client Request Stats
6122 * @hide
6123 */
6124 @Override
6125 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006126 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006127 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006128 return null;
6129 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006130 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006131
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006132 final long identity = Binder.clearCallingIdentity();
6133 try {
6134 if (phone != null) {
6135 return phone.getClientRequestStats();
6136 }
6137
6138 return null;
6139 } finally {
6140 Binder.restoreCallingIdentity(identity);
6141 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006142 }
6143
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006144 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006145 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006146 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006147 }
Jack Yueb4124c2017-02-16 15:32:43 -08006148
6149 /**
Grace Chen70990072017-03-24 17:21:30 -07006150 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006151 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006152 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006153 * @param state State of SIM (power down, power up, pass through)
6154 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6155 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6156 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006157 *
6158 **/
6159 @Override
Grace Chen70990072017-03-24 17:21:30 -07006160 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006161 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006162 Phone phone = PhoneFactory.getPhone(slotIndex);
6163
vagdeviaf9a5b92018-08-15 16:01:53 -07006164 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6165
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006166 final long identity = Binder.clearCallingIdentity();
6167 try {
6168 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006169 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006170 }
6171 } finally {
6172 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006173 }
6174 }
Shuo Qiandd210312017-04-12 22:11:33 +00006175
Tyler Gunn65d45c22017-06-05 11:22:26 -07006176 private boolean isUssdApiAllowed(int subId) {
6177 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006178 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006179 if (configManager == null) {
6180 return false;
6181 }
6182 PersistableBundle pb = configManager.getConfigForSubId(subId);
6183 if (pb == null) {
6184 return false;
6185 }
6186 return pb.getBoolean(
6187 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6188 }
6189
Shuo Qiandd210312017-04-12 22:11:33 +00006190 /**
6191 * Check if phone is in emergency callback mode
6192 * @return true if phone is in emergency callback mode
6193 * @param subId sub id
6194 */
goneil9c5f4872017-12-05 14:07:56 -08006195 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006196 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006197 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006198 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006199
6200 final long identity = Binder.clearCallingIdentity();
6201 try {
6202 if (phone != null) {
6203 return phone.isInEcm();
6204 } else {
6205 return false;
6206 }
6207 } finally {
6208 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006209 }
6210 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006211
6212 /**
6213 * Get the current signal strength information for the given subscription.
6214 * Because this information is not updated when the device is in a low power state
6215 * it should not be relied-upon to be current.
6216 * @param subId Subscription index
6217 * @return the most recent cached signal strength info from the modem
6218 */
6219 @Override
6220 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006221 final long identity = Binder.clearCallingIdentity();
6222 try {
6223 Phone p = getPhone(subId);
6224 if (p == null) {
6225 return null;
6226 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006227
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006228 return p.getSignalStrength();
6229 } finally {
6230 Binder.restoreCallingIdentity(identity);
6231 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006232 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006233
Pengquan Meng77b7f132018-08-22 14:49:57 -07006234 /**
Chen Xuf792fd62018-10-17 17:54:36 +00006235 * Get the current modem radio state for the given slot.
6236 * @param slotIndex slot index.
6237 * @param callingPackage the name of the package making the call.
6238 * @return the current radio power state from the modem
6239 */
6240 @Override
6241 public int getRadioPowerState(int slotIndex, String callingPackage) {
6242 Phone phone = PhoneFactory.getPhone(slotIndex);
6243 if (phone != null) {
6244 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6245 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
6246 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6247 }
6248
6249 final long identity = Binder.clearCallingIdentity();
6250 try {
6251 return phone.getRadioPowerState();
6252 } finally {
6253 Binder.restoreCallingIdentity(identity);
6254 }
6255 }
6256 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6257 }
6258
6259 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07006260 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6261 *
6262 * <p>Requires one of the following permissions:
6263 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6264 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6265 * privileges.
6266 *
6267 * @param subId subscription id
6268 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6269 * {@code false}.
6270 */
6271 @Override
6272 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006273 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6274 null /* message */);
6275
Pengquan Menga1bb6272018-09-06 09:59:22 -07006276 boolean isEnabled = false;
6277 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07006278 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006279 Phone phone = getPhone(subId);
6280 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006281 } catch (Exception e) {
6282 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6283 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07006284 } finally {
6285 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006286 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006287 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006288 }
6289
6290
6291 /**
6292 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6293 *
6294 * <p> Requires permission:
6295 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6296 * privileges.
6297 *
6298 * @param subId subscription id
6299 * @param isEnabled {@code true} means enable, {@code false} means disable.
6300 */
6301 @Override
6302 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006303 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6304 mApp, subId, "setDataRoamingEnabled");
6305
Pengquan Menga1bb6272018-09-06 09:59:22 -07006306 final long identity = Binder.clearCallingIdentity();
6307 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006308 Phone phone = getPhone(subId);
6309 if (phone != null) {
6310 phone.setDataRoamingEnabled(isEnabled);
6311 }
6312 } finally {
6313 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006314 }
6315 }
6316
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006317 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006318 public boolean isManualNetworkSelectionAllowed(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006319 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6320 mApp, subId, "isManualNetworkSelectionAllowed");
6321
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006322 boolean isAllowed = true;
6323 final long identity = Binder.clearCallingIdentity();
6324 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006325 Phone phone = getPhone(subId);
6326 if (phone != null) {
6327 isAllowed = phone.isCspPlmnEnabled();
6328 }
6329 } finally {
6330 Binder.restoreCallingIdentity(identity);
6331 }
6332 return isAllowed;
6333 }
6334
6335 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006336 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006337 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08006338 try {
6339 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07006340 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08006341 } catch (SecurityException e) {
6342 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6343 // has carrier privileges on an active UICC
6344 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6345 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006346 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08006347 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006348 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006349
6350 final long identity = Binder.clearCallingIdentity();
6351 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006352 UiccController uiccController = UiccController.getInstance();
6353 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07006354 if (hasReadPermission) {
6355 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006356 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07006357
6358 // Remove private info if the caller doesn't have access
6359 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6360 for (UiccCardInfo cardInfo : cardInfos) {
6361 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6362 // is available
6363 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
6364 if (card == null || card.getUiccProfile() == null) {
6365 // assume no access if the card or profile is unavailable
6366 filteredInfos.add(cardInfo.getUnprivileged());
6367 continue;
6368 }
6369 UiccProfile profile = card.getUiccProfile();
6370 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6371 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6372 filteredInfos.add(cardInfo);
6373 } else {
6374 filteredInfos.add(cardInfo.getUnprivileged());
6375 }
6376 }
6377 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08006378 } finally {
6379 Binder.restoreCallingIdentity(identity);
6380 }
6381 }
6382
6383 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006384 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006385 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006386
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006387 final long identity = Binder.clearCallingIdentity();
6388 try {
6389 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6390 if (slots == null) {
6391 Rlog.i(LOG_TAG, "slots is null.");
6392 return null;
6393 }
6394
6395 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6396 for (int i = 0; i < slots.length; i++) {
6397 UiccSlot slot = slots[i];
6398 if (slot == null) {
6399 continue;
6400 }
6401
Jordan Liu7be7e652019-05-06 18:55:02 +00006402 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006403 UiccCard card = slot.getUiccCard();
6404 if (card != null) {
6405 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00006406 } else {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006407 cardId = slot.getIccId();
6408 }
6409
6410 int cardState = 0;
6411 switch (slot.getCardState()) {
6412 case CARDSTATE_ABSENT:
6413 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6414 break;
6415 case CARDSTATE_PRESENT:
6416 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6417 break;
6418 case CARDSTATE_ERROR:
6419 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6420 break;
6421 case CARDSTATE_RESTRICTED:
6422 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6423 break;
6424 default:
6425 break;
6426
6427 }
6428
6429 infos[i] = new UiccSlotInfo(
6430 slot.isActive(),
6431 slot.isEuicc(),
6432 cardId,
6433 cardState,
6434 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08006435 slot.isExtendedApduSupported(),
6436 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006437 }
6438 return infos;
6439 } finally {
6440 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006441 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006442 }
6443
6444 @Override
6445 public boolean switchSlots(int[] physicalSlots) {
6446 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006447
6448 final long identity = Binder.clearCallingIdentity();
6449 try {
6450 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6451 } finally {
6452 Binder.restoreCallingIdentity(identity);
6453 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006454 }
Jack Yu4c988042018-02-27 15:30:01 -08006455
6456 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006457 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006458 final long identity = Binder.clearCallingIdentity();
6459 try {
6460 return UiccController.getInstance().getCardIdForDefaultEuicc();
6461 } finally {
6462 Binder.restoreCallingIdentity(identity);
6463 }
6464 }
6465
6466 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006467 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6468 enforceModifyPermission();
6469 final Phone phone = getPhone(subId);
6470 if (phone == null) {
6471 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6472 return;
6473 }
6474
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006475 final long identity = Binder.clearCallingIdentity();
6476 try {
6477 phone.setRadioIndicationUpdateMode(filters, mode);
6478 } finally {
6479 Binder.restoreCallingIdentity(identity);
6480 }
Jack Yu4c988042018-02-27 15:30:01 -08006481 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006482
6483 /**
goneil47ffb6e2018-04-06 15:40:58 -07006484 * A test API to reload the UICC profile.
6485 *
6486 * <p>Requires that the calling app has permission
6487 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6488 * @hide
6489 */
6490 @Override
6491 public void refreshUiccProfile(int subId) {
6492 enforceModifyPermission();
6493
6494 final long identity = Binder.clearCallingIdentity();
6495 try {
6496 Phone phone = getPhone(subId);
6497 if (phone == null) {
6498 return;
6499 }
6500 UiccCard uiccCard = phone.getUiccCard();
6501 if (uiccCard == null) {
6502 return;
6503 }
6504 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6505 if (uiccProfile == null) {
6506 return;
6507 }
6508 uiccProfile.refresh();
6509 } finally {
6510 Binder.restoreCallingIdentity(identity);
6511 }
6512 }
6513
6514 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006515 * Returns false if the mobile data is disabled by default, otherwise return true.
6516 */
6517 private boolean getDefaultDataEnabled() {
6518 return "true".equalsIgnoreCase(
6519 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
6520 }
6521
6522 /**
6523 * Returns true if the data roaming is enabled by default, i.e the system property
6524 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
6525 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
6526 */
6527 private boolean getDefaultDataRoamingEnabled(int subId) {
6528 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006529 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006530 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
6531 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
6532 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
6533 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
6534 return isDataRoamingEnabled;
6535 }
6536
6537 /**
6538 * Returns the default network type for the given {@code subId}, if the default network type is
6539 * not set, return {@link Phone#PREFERRED_NT_MODE}.
6540 */
6541 private int getDefaultNetworkType(int subId) {
6542 return Integer.parseInt(
6543 TelephonyManager.getTelephonyProperty(
6544 mSubscriptionController.getPhoneId(subId),
6545 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
6546 String.valueOf(Phone.PREFERRED_NT_MODE)));
6547 }
fionaxua13278b2018-03-21 00:08:13 -07006548
6549 @Override
6550 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07006551 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07006552 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006553
6554 final long identity = Binder.clearCallingIdentity();
6555 try {
6556 final Phone phone = getPhone(subId);
6557 if (phone == null) {
6558 loge("setCarrierTestOverride fails with invalid subId: " + subId);
6559 return;
6560 }
chen xueaba88a2019-03-15 13:15:10 -07006561 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
6562 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006563 } finally {
6564 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006565 }
fionaxua13278b2018-03-21 00:08:13 -07006566 }
6567
6568 @Override
6569 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006570 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006571
6572 final long identity = Binder.clearCallingIdentity();
6573 try {
6574 final Phone phone = getPhone(subId);
6575 if (phone == null) {
6576 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
6577 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
6578 }
6579 return phone.getCarrierIdListVersion();
6580 } finally {
6581 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006582 }
fionaxua13278b2018-03-21 00:08:13 -07006583 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07006584
6585 @Override
6586 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
6587 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6588 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
6589 return -1;
6590 }
6591
6592 final long identity = Binder.clearCallingIdentity();
6593 try {
6594 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
6595 } finally {
6596 Binder.restoreCallingIdentity(identity);
6597 }
6598 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006599
6600 @Override
6601 public int getCdmaRoamingMode(int subId) {
6602 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6603 mApp, subId, "getCdmaRoamingMode");
6604
6605 final long identity = Binder.clearCallingIdentity();
6606 try {
6607 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
6608 } finally {
6609 Binder.restoreCallingIdentity(identity);
6610 }
6611 }
6612
6613 @Override
6614 public boolean setCdmaRoamingMode(int subId, int mode) {
6615 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6616 mApp, subId, "setCdmaRoamingMode");
6617
6618 final long identity = Binder.clearCallingIdentity();
6619 try {
6620 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
6621 } finally {
6622 Binder.restoreCallingIdentity(identity);
6623 }
6624 }
6625
6626 @Override
6627 public boolean setCdmaSubscriptionMode(int subId, int mode) {
6628 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6629 mApp, subId, "setCdmaSubscriptionMode");
6630
6631 final long identity = Binder.clearCallingIdentity();
6632 try {
6633 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
6634 } finally {
6635 Binder.restoreCallingIdentity(identity);
6636 }
6637 }
Makoto Onukida3bf792018-09-18 16:06:29 -07006638
6639 private void ensureUserRunning(int userId) {
6640 if (!mUserManager.isUserRunning(userId)) {
6641 throw new IllegalStateException("User " + userId + " does not exist or not running");
6642 }
6643 }
6644
6645 /**
6646 * Returns a list of SMS apps on a given user.
6647 *
6648 * Only the shell user (UID 2000 or 0) can call it.
6649 * Target user must be running.
6650 */
6651 @Override
6652 public String[] getSmsApps(int userId) {
6653 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
6654 ensureUserRunning(userId);
6655
6656 final Collection<SmsApplicationData> apps =
6657 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
6658
6659 String[] ret = new String[apps.size()];
6660 int i = 0;
6661 for (SmsApplicationData app : apps) {
6662 ret[i++] = app.mPackageName;
6663 }
6664 return ret;
6665 }
6666
6667 /**
6668 * Returns the default SMS app package name on a given user.
6669 *
6670 * Only the shell user (UID 2000 or 0) can call it.
6671 * Target user must be running.
6672 */
6673 @Override
6674 public String getDefaultSmsApp(int userId) {
6675 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
6676 ensureUserRunning(userId);
6677
6678 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
6679 /* updateIfNeeded= */ true, userId);
6680 return cn == null ? null : cn.getPackageName();
6681 }
6682
6683 /**
6684 * Set a package as the default SMS app on a given user.
6685 *
6686 * Only the shell user (UID 2000 or 0) can call it.
6687 * Target user must be running.
6688 */
6689 @Override
6690 public void setDefaultSmsApp(int userId, String packageName) {
6691 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
6692 ensureUserRunning(userId);
6693
6694 boolean found = false;
6695 for (String pkg : getSmsApps(userId)) {
6696 if (TextUtils.equals(packageName, pkg)) {
6697 found = true;
6698 break;
6699 }
6700 }
6701 if (!found) {
6702 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
6703 }
6704
6705 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
6706 }
sqianc5eccab2018-10-19 18:46:41 -07006707
6708 @Override
sqian8c685422019-02-22 15:55:18 -08006709 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
sqianc5eccab2018-10-19 18:46:41 -07006710 String callingPackage) {
sqian11b7a0e2018-12-05 18:48:28 -08006711 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
sqian8c685422019-02-22 15:55:18 -08006712 mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08006713 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6714 }
6715 final long identity = Binder.clearCallingIdentity();
6716 try {
sqian854d44b2018-12-12 16:48:18 -08006717 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
6718 for (Phone phone: PhoneFactory.getPhones()) {
6719 if (phone.getEmergencyNumberTracker() != null
6720 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
6721 emergencyNumberListInternal.put(
6722 phone.getSubId(),
6723 phone.getEmergencyNumberTracker().getEmergencyNumberList());
6724 }
sqian11b7a0e2018-12-05 18:48:28 -08006725 }
sqian854d44b2018-12-12 16:48:18 -08006726 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08006727 } finally {
6728 Binder.restoreCallingIdentity(identity);
6729 }
sqianc5eccab2018-10-19 18:46:41 -07006730 }
6731
6732 @Override
sqian8c685422019-02-22 15:55:18 -08006733 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006734 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08006735 if (!exactMatch) {
6736 TelephonyPermissions
6737 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08006738 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08006739 }
6740 final long identity = Binder.clearCallingIdentity();
6741 try {
sqian854d44b2018-12-12 16:48:18 -08006742 for (Phone phone: PhoneFactory.getPhones()) {
6743 if (phone.getEmergencyNumberTracker() != null
6744 && phone.getEmergencyNumberTracker() != null) {
6745 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
6746 number, exactMatch)) {
6747 return true;
sqian11b7a0e2018-12-05 18:48:28 -08006748 }
6749 }
sqian11b7a0e2018-12-05 18:48:28 -08006750 }
6751 return false;
6752 } finally {
6753 Binder.restoreCallingIdentity(identity);
6754 }
6755 }
6756
sqianf4ca7ed2019-01-15 18:32:07 -08006757 /**
6758 * Update emergency number list for test mode.
6759 */
6760 @Override
6761 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
6762 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6763 "updateEmergencyNumberListTestMode");
6764
6765 final long identity = Binder.clearCallingIdentity();
6766 try {
6767 for (Phone phone: PhoneFactory.getPhones()) {
6768 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6769 if (tracker != null) {
6770 tracker.executeEmergencyNumberTestModeCommand(action, num);
6771 }
6772 }
6773 } finally {
6774 Binder.restoreCallingIdentity(identity);
6775 }
6776 }
6777
6778 /**
6779 * Get the full emergency number list for test mode.
6780 */
6781 @Override
6782 public List<String> getEmergencyNumberListTestMode() {
6783 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6784 "getEmergencyNumberListTestMode");
6785
6786 final long identity = Binder.clearCallingIdentity();
6787 try {
6788 Set<String> emergencyNumbers = new HashSet<>();
6789 for (Phone phone: PhoneFactory.getPhones()) {
6790 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6791 if (tracker != null) {
6792 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
6793 emergencyNumbers.add(num.getNumber());
6794 }
6795 }
6796 }
6797 return new ArrayList<>(emergencyNumbers);
6798 } finally {
6799 Binder.restoreCallingIdentity(identity);
6800 }
6801 }
6802
chen xud6b45bd2018-10-30 22:27:10 -07006803 @Override
6804 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
6805 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
6806 Phone phone = getPhone(subId);
6807 if (phone == null) {
6808 return null;
6809 }
6810 final long identity = Binder.clearCallingIdentity();
6811 try {
6812 UiccProfile profile = UiccController.getInstance()
6813 .getUiccProfileForPhone(phone.getPhoneId());
6814 if (profile != null) {
6815 return profile.getCertsFromCarrierPrivilegeAccessRules();
6816 }
6817 } finally {
6818 Binder.restoreCallingIdentity(identity);
6819 }
6820 return null;
6821 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08006822
6823 /**
6824 * Enable or disable a modem stack.
6825 */
6826 @Override
6827 public boolean enableModemForSlot(int slotIndex, boolean enable) {
6828 enforceModifyPermission();
6829
6830 final long identity = Binder.clearCallingIdentity();
6831 try {
6832 Phone phone = PhoneFactory.getPhone(slotIndex);
6833 if (phone == null) {
6834 return false;
6835 } else {
6836 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
6837 }
6838 } finally {
6839 Binder.restoreCallingIdentity(identity);
6840 }
6841 }
Michelecea4cf22018-12-21 15:00:11 -08006842
Malcolm Chen4bcd9822019-03-27 18:34:05 -07006843 /**
6844 * Whether a modem stack is enabled or not.
6845 */
6846 @Override
6847 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage) {
6848 Phone phone = PhoneFactory.getPhone(slotIndex);
6849 if (phone == null) return false;
6850
6851 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6852 mApp, phone.getSubId(), callingPackage, "isModemEnabledForSlot")) {
6853 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6854 }
6855
6856 final long identity = Binder.clearCallingIdentity();
6857 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07006858 try {
6859 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
6860 } catch (NoSuchElementException ex) {
6861 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
6862 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07006863 } finally {
6864 Binder.restoreCallingIdentity(identity);
6865 }
6866 }
6867
Michelecea4cf22018-12-21 15:00:11 -08006868 @Override
Michele0ea7d782019-03-19 14:58:42 -07006869 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08006870 enforceModifyPermission();
6871
6872 final long identity = Binder.clearCallingIdentity();
6873 try {
6874 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07006875 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08006876 .commit();
6877 } finally {
6878 Binder.restoreCallingIdentity(identity);
6879 }
6880 }
6881
6882 @Override
Michele0ea7d782019-03-19 14:58:42 -07006883 @TelephonyManager.IsMultiSimSupportedResult
6884 public int isMultiSimSupported(String callingPackage) {
Michele4245e952019-02-04 11:36:23 -08006885 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Michele0ea7d782019-03-19 14:58:42 -07006886 getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) {
6887 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08006888 }
Michelecea4cf22018-12-21 15:00:11 -08006889
6890 final long identity = Binder.clearCallingIdentity();
6891 try {
Michele0ea7d782019-03-19 14:58:42 -07006892 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08006893 } finally {
6894 Binder.restoreCallingIdentity(identity);
6895 }
6896 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006897
Michele0ea7d782019-03-19 14:58:42 -07006898 @TelephonyManager.IsMultiSimSupportedResult
6899 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08006900 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
6901 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
6902 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07006903 loge("isMultiSimSupportedInternal: requires at least 2 cards");
6904 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006905 }
6906 // Check if the hardware supports multisim functionality. If usage of multisim is not
6907 // supported by the modem, indicate that it is restricted.
6908 PhoneCapability staticCapability =
6909 mPhoneConfigurationManager.getStaticPhoneCapability();
6910 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07006911 loge("isMultiSimSupportedInternal: no static configuration available");
6912 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006913 }
6914 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07006915 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
6916 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006917 }
6918 // Check if support of multiple SIMs is restricted by carrier
6919 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07006920 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08006921 }
6922
Michele0ea7d782019-03-19 14:58:42 -07006923 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08006924 }
6925
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006926 /**
6927 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08006928 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
6929 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
6930 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006931 * @param numOfSims number of active sims we want to switch to
6932 */
6933 @Override
6934 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08006935 if (numOfSims == 1) {
6936 enforceModifyPermission();
6937 } else {
6938 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6939 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
6940 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006941 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08006942
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006943 try {
Michele30b57b22019-03-01 12:01:14 -08006944 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07006945 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08006946 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
6947 return;
6948 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006949 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
6950 } finally {
6951 Binder.restoreCallingIdentity(identity);
6952 }
6953 }
6954
6955 /**
chen xub4baa772019-04-03 10:23:41 -07006956 * Get whether making changes to modem configurations will trigger reboot.
6957 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08006958 */
6959 @Override
chen xub4baa772019-04-03 10:23:41 -07006960 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage) {
6961 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6962 mApp, subId, callingPackage, "doesSwitchMultiSimConfigTriggerReboot")) {
6963 return false;
6964 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08006965 final long identity = Binder.clearCallingIdentity();
6966 try {
6967 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
6968 } finally {
6969 Binder.restoreCallingIdentity(identity);
6970 }
6971 }
6972
Nathan Harold29f5f052019-02-15 13:41:57 -08006973 private void updateModemStateMetrics() {
6974 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
6975 // TODO: check the state for each modem if the api is ready.
6976 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
6977 }
6978
Pengquan Meng3889a572019-01-23 11:16:29 -08006979 @Override
6980 public int[] getSlotsMapping() {
6981 enforceReadPrivilegedPermission("getSlotsMapping");
6982
6983 final long identity = Binder.clearCallingIdentity();
6984 try {
6985 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
6986 // All logical slots should have a mapping to a physical slot.
6987 int[] logicalSlotsMapping = new int[phoneCount];
6988 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
6989 for (int i = 0; i < slotInfos.length; i++) {
6990 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
6991 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
6992 }
6993 }
6994 return logicalSlotsMapping;
6995 } finally {
6996 Binder.restoreCallingIdentity(identity);
6997 }
6998 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08006999
7000 /**
7001 * Get the IRadio HAL Version
7002 */
7003 @Override
7004 public int getRadioHalVersion() {
7005 Phone phone = getDefaultPhone();
7006 if (phone == null) return -1;
7007 HalVersion hv = phone.getHalVersion();
7008 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7009 return hv.major * 100 + hv.minor;
7010 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007011
7012 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007013 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7014 * corresponding network requests on a subId.
7015 *
7016 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007017 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007018 * 2) APN is un-metered for this subscription, or
7019 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
7020 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on.
7021 *
7022 * @return whether data is allowed for a apn type.
7023 *
7024 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007025 */
7026 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007027 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007028 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Malcolm Chene5ad5792019-04-18 13:51:02 -07007029 mApp, subId, callingPackage, "isDataEnabledForApn")) {
7030 throw new SecurityException("Needs READ_PHONE_STATE for isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007031 }
7032
7033 // Now that all security checks passes, perform the operation as ourselves.
7034 final long identity = Binder.clearCallingIdentity();
7035 try {
7036 Phone phone = getPhone(subId);
7037 if (phone == null) return false;
7038
7039 boolean isMetered = ApnSettingUtils.isMeteredApnType(ApnSetting.getApnTypeString(
Malcolm Chene5ad5792019-04-18 13:51:02 -07007040 apnType), phone);
7041 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7042 } finally {
7043 Binder.restoreCallingIdentity(identity);
7044 }
7045 }
7046
7047 @Override
7048 public boolean isApnMetered(int apnType, int subId) {
7049 enforceReadPrivilegedPermission("isApnMetered");
7050
7051 // Now that all security checks passes, perform the operation as ourselves.
7052 final long identity = Binder.clearCallingIdentity();
7053 try {
7054 Phone phone = getPhone(subId);
7055 if (phone == null) return true; // By default return true.
7056
7057 return ApnSettingUtils.isMeteredApnType(ApnSetting.getApnTypeString(
7058 apnType), phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007059 } finally {
7060 Binder.restoreCallingIdentity(identity);
7061 }
7062 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007063}