blob: f391b5acf1ad41c24e75052057cc1ccb6adbecaf [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;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700124import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800125import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700126import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800127import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700128import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100129import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700130import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700131import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700132import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700133import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800134import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700135import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700136import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700137import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700138import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700139import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700140import com.android.internal.telephony.ServiceStateTracker;
Makoto Onukida3bf792018-09-18 16:06:29 -0700141import com.android.internal.telephony.SmsApplication;
142import com.android.internal.telephony.SmsApplication.SmsApplicationData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700143import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800144import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800145import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700146import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800147import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700148import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800149import com.android.internal.telephony.ims.ImsResolver;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800150import com.android.internal.telephony.metrics.TelephonyMetrics;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700151import com.android.internal.telephony.uicc.IccIoResult;
152import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800153import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700154import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800155import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700156import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800157import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000158import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700159import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800160import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700161import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700162import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800163import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700164import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700165import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800166
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700167import java.io.FileDescriptor;
168import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800169import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700170import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800171import java.util.Arrays;
Makoto Onukida3bf792018-09-18 16:06:29 -0700172import java.util.Collection;
sqian11b7a0e2018-12-05 18:48:28 -0800173import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800174import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800175import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100176import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800177import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700178import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800179import java.util.Set;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700180
181/**
182 * Implementation of the ITelephony interface.
183 */
Santos Cordon117fee72014-05-16 17:56:12 -0700184public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700185 private static final String LOG_TAG = "PhoneInterfaceManager";
186 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
187 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800188 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700189
190 // Message codes used with mMainThreadHandler
191 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700192 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
193 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700194 private static final int CMD_OPEN_CHANNEL = 9;
195 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
196 private static final int CMD_CLOSE_CHANNEL = 11;
197 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800198 private static final int CMD_NV_READ_ITEM = 13;
199 private static final int EVENT_NV_READ_ITEM_DONE = 14;
200 private static final int CMD_NV_WRITE_ITEM = 15;
201 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
202 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
203 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700204 private static final int CMD_RESET_MODEM_CONFIG = 19;
205 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800206 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
207 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
208 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
209 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800210 private static final int CMD_SEND_ENVELOPE = 25;
211 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000212 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
213 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700214 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
215 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
216 private static final int CMD_EXCHANGE_SIM_IO = 31;
217 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800218 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
219 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700220 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
221 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700222 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
223 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700224 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
225 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
226 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
227 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700228 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
229 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
230 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
231 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700232 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800233 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
234 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000235 private static final int CMD_SWITCH_SLOTS = 50;
236 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700237 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
238 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
239 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
240 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
241 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
242 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
243 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
244 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700245 private static final int CMD_GET_ALL_CELL_INFO = 60;
246 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
247 private static final int CMD_GET_CELL_LOCATION = 62;
248 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700249 private static final int CMD_MODEM_REBOOT = 64;
250 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700251 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
252 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800253 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
254 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700255 private static final int CMD_GET_MODEM_STATUS = 70;
256 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700257
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800258 // Parameters of select command.
259 private static final int SELECT_COMMAND = 0xA4;
260 private static final int SELECT_P1 = 0x04;
261 private static final int SELECT_P2 = 0;
262 private static final int SELECT_P3 = 0x10;
263
Pengquan Meng85728fb2018-03-12 16:31:21 -0700264 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
265 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
266 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
267
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700268 /** The singleton instance. */
269 private static PhoneInterfaceManager sInstance;
270
Wink Saville3ab207e2014-11-20 13:07:20 -0800271 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800272 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700273 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800274 private AppOpsManager mAppOps;
275 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800276 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800277 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700278 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700279
Derek Tan97ebb422014-09-05 16:55:38 -0700280 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
281 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800282 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800283 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700284
Michelecea4cf22018-12-21 15:00:11 -0800285 // String to store multi SIM allowed
286 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
287
Derek Tan740e1672017-06-27 14:56:27 -0700288 // The AID of ISD-R.
289 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
290
yinxub1bed742017-04-17 11:45:04 -0700291 private NetworkScanRequestTracker mNetworkScanRequestTracker;
292
David Kelly5e06a7f2018-03-12 14:10:59 +0000293 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
294 private static final int MANUFACTURER_CODE_LENGTH = 8;
295
Derek Tan89e89d42014-07-08 17:00:10 -0700296 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700297 * A request object to use for transmitting data to an ICC.
298 */
299 private static final class IccAPDUArgument {
300 public int channel, cla, command, p1, p2, p3;
301 public String data;
302
303 public IccAPDUArgument(int channel, int cla, int command,
304 int p1, int p2, int p3, String data) {
305 this.channel = channel;
306 this.cla = cla;
307 this.command = command;
308 this.p1 = p1;
309 this.p2 = p2;
310 this.p3 = p3;
311 this.data = data;
312 }
313 }
314
315 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700316 * A request object to use for transmitting data to an ICC.
317 */
318 private static final class ManualNetworkSelectionArgument {
319 public OperatorInfo operatorInfo;
320 public boolean persistSelection;
321
322 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
323 this.operatorInfo = operatorInfo;
324 this.persistSelection = persistSelection;
325 }
326 }
327
328 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700329 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
330 * request after sending. The main thread will notify the request when it is complete.
331 */
332 private static final class MainThreadRequest {
333 /** The argument to use for the request */
334 public Object argument;
335 /** The result of the request that is run on the main thread */
336 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800337 // The subscriber id that this request applies to. Defaults to
338 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
339 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700340
Nathan Harold92bed182018-10-12 18:16:49 -0700341 // In cases where subId is unavailable, the caller needs to specify the phone.
342 public Phone phone;
343
vagdeviaf9a5b92018-08-15 16:01:53 -0700344 public WorkSource workSource;
345
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700346 public MainThreadRequest(Object argument) {
347 this.argument = argument;
348 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800349
Nathan Harold92bed182018-10-12 18:16:49 -0700350 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
351 this.argument = argument;
352 if (phone != null) {
353 this.phone = phone;
354 }
355 this.workSource = workSource;
356 }
357
vagdeviaf9a5b92018-08-15 16:01:53 -0700358 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800359 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800360 if (subId != null) {
361 this.subId = subId;
362 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700363 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800364 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700365 }
366
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800367 private static final class IncomingThirdPartyCallArgs {
368 public final ComponentName component;
369 public final String callId;
370 public final String callerDisplayName;
371
372 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
373 String callerDisplayName) {
374 this.component = component;
375 this.callId = callId;
376 this.callerDisplayName = callerDisplayName;
377 }
378 }
379
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700380 /**
381 * A handler that processes messages on the main thread in the phone process. Since many
382 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
383 * inbound binder threads to the main thread in the phone process. The Binder thread
384 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
385 * on, which will be notified when the operation completes and will contain the result of the
386 * request.
387 *
388 * <p>If a MainThreadRequest object is provided in the msg.obj field,
389 * note that request.result must be set to something non-null for the calling thread to
390 * unblock.
391 */
392 private final class MainThreadHandler extends Handler {
393 @Override
394 public void handleMessage(Message msg) {
395 MainThreadRequest request;
396 Message onCompleted;
397 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800398 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700399 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800400 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700401
402 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700403 case CMD_HANDLE_USSD_REQUEST: {
404 request = (MainThreadRequest) msg.obj;
405 final Phone phone = getPhoneFromRequest(request);
406 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
407 String ussdRequest = ussdObject.first;
408 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700409
Pengquan Menga1bb6272018-09-06 09:59:22 -0700410 if (!isUssdApiAllowed(request.subId)) {
411 // Carrier does not support use of this API, return failure.
412 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
413 UssdResponse response = new UssdResponse(ussdRequest, null);
414 Bundle returnData = new Bundle();
415 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
416 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700417
Pengquan Menga1bb6272018-09-06 09:59:22 -0700418 request.result = true;
419 notifyRequester(request);
420 return;
421 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700422
Pengquan Menga1bb6272018-09-06 09:59:22 -0700423 try {
424 request.result = phone != null
425 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
426 } catch (CallStateException cse) {
427 request.result = false;
428 }
429 // Wake up the requesting thread
430 notifyRequester(request);
431 break;
pkanwar32d516d2016-10-14 19:37:38 -0700432 }
433
Yorke Lee716f67e2015-06-17 15:39:16 -0700434 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700435 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700436 final Phone phone = getPhoneFromRequest(request);
437 request.result = phone != null ?
438 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
439 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700440 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700441 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700442 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700443 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700444
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700445 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700446 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700447 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800448 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700449 if (uiccCard == null) {
450 loge("iccTransmitApduLogicalChannel: No UICC");
451 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700452 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700453 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700454 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
455 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700456 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700457 iccArgument.channel, iccArgument.cla, iccArgument.command,
458 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700459 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700460 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700461 break;
462
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700463 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700464 ar = (AsyncResult) msg.obj;
465 request = (MainThreadRequest) ar.userObj;
466 if (ar.exception == null && ar.result != null) {
467 request.result = ar.result;
468 } else {
469 request.result = new IccIoResult(0x6F, 0, (byte[])null);
470 if (ar.result == null) {
471 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800472 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700473 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800474 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700475 } else {
476 loge("iccTransmitApduLogicalChannel: Unknown exception");
477 }
478 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700479 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700480 break;
481
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700482 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
483 request = (MainThreadRequest) msg.obj;
484 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800485 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700486 if (uiccCard == null) {
487 loge("iccTransmitApduBasicChannel: No UICC");
488 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700489 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700490 } else {
491 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
492 request);
493 uiccCard.iccTransmitApduBasicChannel(
494 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
495 iccArgument.p3, iccArgument.data, onCompleted);
496 }
497 break;
498
499 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
500 ar = (AsyncResult) msg.obj;
501 request = (MainThreadRequest) ar.userObj;
502 if (ar.exception == null && ar.result != null) {
503 request.result = ar.result;
504 } else {
505 request.result = new IccIoResult(0x6F, 0, (byte[])null);
506 if (ar.result == null) {
507 loge("iccTransmitApduBasicChannel: Empty response");
508 } else if (ar.exception instanceof CommandException) {
509 loge("iccTransmitApduBasicChannel: CommandException: " +
510 ar.exception);
511 } else {
512 loge("iccTransmitApduBasicChannel: Unknown exception");
513 }
514 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700515 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700516 break;
517
518 case CMD_EXCHANGE_SIM_IO:
519 request = (MainThreadRequest) msg.obj;
520 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800521 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700522 if (uiccCard == null) {
523 loge("iccExchangeSimIO: No UICC");
524 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700525 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700526 } else {
527 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
528 request);
529 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
530 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
531 iccArgument.data, onCompleted);
532 }
533 break;
534
535 case EVENT_EXCHANGE_SIM_IO_DONE:
536 ar = (AsyncResult) msg.obj;
537 request = (MainThreadRequest) ar.userObj;
538 if (ar.exception == null && ar.result != null) {
539 request.result = ar.result;
540 } else {
541 request.result = new IccIoResult(0x6f, 0, (byte[])null);
542 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700543 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700544 break;
545
Derek Tan4d5e5c12014-02-04 11:54:58 -0800546 case CMD_SEND_ENVELOPE:
547 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800548 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700549 if (uiccCard == null) {
550 loge("sendEnvelopeWithStatus: No UICC");
551 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700552 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700553 } else {
554 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
555 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
556 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800557 break;
558
559 case EVENT_SEND_ENVELOPE_DONE:
560 ar = (AsyncResult) msg.obj;
561 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700562 if (ar.exception == null && ar.result != null) {
563 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800564 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700565 request.result = new IccIoResult(0x6F, 0, (byte[])null);
566 if (ar.result == null) {
567 loge("sendEnvelopeWithStatus: Empty response");
568 } else if (ar.exception instanceof CommandException) {
569 loge("sendEnvelopeWithStatus: CommandException: " +
570 ar.exception);
571 } else {
572 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
573 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800574 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700575 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800576 break;
577
Shishir Agrawal566b7612013-10-28 14:41:00 -0700578 case CMD_OPEN_CHANNEL:
579 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800580 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800581 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700582 if (uiccCard == null) {
583 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800584 request.result = new IccOpenLogicalChannelResponse(-1,
585 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700586 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700587 } else {
588 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800589 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
590 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700591 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700592 break;
593
594 case EVENT_OPEN_CHANNEL_DONE:
595 ar = (AsyncResult) msg.obj;
596 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700597 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700598 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700599 int[] result = (int[]) ar.result;
600 int channelId = result[0];
601 byte[] selectResponse = null;
602 if (result.length > 1) {
603 selectResponse = new byte[result.length - 1];
604 for (int i = 1; i < result.length; ++i) {
605 selectResponse[i - 1] = (byte) result[i];
606 }
607 }
608 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700609 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700610 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700611 if (ar.result == null) {
612 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700613 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700614 if (ar.exception != null) {
615 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
616 }
617
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700618 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700619 if (ar.exception instanceof CommandException) {
620 CommandException.Error error =
621 ((CommandException) (ar.exception)).getCommandError();
622 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700623 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700624 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700625 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700626 }
627 }
628 openChannelResp = new IccOpenLogicalChannelResponse(
629 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700630 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700631 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700632 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700633 break;
634
635 case CMD_CLOSE_CHANNEL:
636 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800637 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700638 if (uiccCard == null) {
639 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900640 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700641 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700642 } else {
643 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
644 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
645 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700646 break;
647
648 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800649 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
650 break;
651
652 case CMD_NV_READ_ITEM:
653 request = (MainThreadRequest) msg.obj;
654 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800655 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
656 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800657 break;
658
659 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700660 ar = (AsyncResult) msg.obj;
661 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800662 if (ar.exception == null && ar.result != null) {
663 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700664 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800665 request.result = "";
666 if (ar.result == null) {
667 loge("nvReadItem: Empty response");
668 } else if (ar.exception instanceof CommandException) {
669 loge("nvReadItem: CommandException: " +
670 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700671 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800672 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700673 }
674 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700675 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700676 break;
677
Jake Hambye994d462014-02-03 13:10:13 -0800678 case CMD_NV_WRITE_ITEM:
679 request = (MainThreadRequest) msg.obj;
680 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
681 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800682 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700683 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800684 break;
685
686 case EVENT_NV_WRITE_ITEM_DONE:
687 handleNullReturnEvent(msg, "nvWriteItem");
688 break;
689
690 case CMD_NV_WRITE_CDMA_PRL:
691 request = (MainThreadRequest) msg.obj;
692 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800693 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800694 break;
695
696 case EVENT_NV_WRITE_CDMA_PRL_DONE:
697 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
698 break;
699
chen xu6dac5ab2018-10-26 17:39:23 -0700700 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800701 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700702 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800703 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800704 break;
705
chen xu6dac5ab2018-10-26 17:39:23 -0700706 case EVENT_RESET_MODEM_CONFIG_DONE:
707 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800708 break;
709
Jake Hamby7c27be32014-03-03 13:25:59 -0800710 case CMD_GET_PREFERRED_NETWORK_TYPE:
711 request = (MainThreadRequest) msg.obj;
712 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700713 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800714 break;
715
716 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
717 ar = (AsyncResult) msg.obj;
718 request = (MainThreadRequest) ar.userObj;
719 if (ar.exception == null && ar.result != null) {
720 request.result = ar.result; // Integer
721 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800722 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800723 if (ar.result == null) {
724 loge("getPreferredNetworkType: Empty response");
725 } else if (ar.exception instanceof CommandException) {
726 loge("getPreferredNetworkType: CommandException: " +
727 ar.exception);
728 } else {
729 loge("getPreferredNetworkType: Unknown exception");
730 }
731 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700732 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800733 break;
734
735 case CMD_SET_PREFERRED_NETWORK_TYPE:
736 request = (MainThreadRequest) msg.obj;
737 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
738 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700739 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800740 break;
741
742 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
743 handleNullReturnEvent(msg, "setPreferredNetworkType");
744 break;
745
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000746 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
747 request = (MainThreadRequest)msg.obj;
748 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800749 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000750 break;
751
752 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
753 ar = (AsyncResult)msg.obj;
754 request = (MainThreadRequest)ar.userObj;
755 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700756 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000757 break;
758
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800759 case CMD_SET_VOICEMAIL_NUMBER:
760 request = (MainThreadRequest) msg.obj;
761 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
762 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800763 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
764 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800765 break;
766
767 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
768 handleNullReturnEvent(msg, "setVoicemailNumber");
769 break;
770
Stuart Scott54788802015-03-30 13:18:01 -0700771 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
772 request = (MainThreadRequest) msg.obj;
773 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
774 request);
775 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
776 break;
777
778 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
779 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
780 break;
781
Shishir Agrawal302c8692015-06-19 13:49:39 -0700782 case CMD_PERFORM_NETWORK_SCAN:
783 request = (MainThreadRequest) msg.obj;
784 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
785 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
786 break;
787
788 case EVENT_PERFORM_NETWORK_SCAN_DONE:
789 ar = (AsyncResult) msg.obj;
790 request = (MainThreadRequest) ar.userObj;
791 CellNetworkScanResult cellScanResult;
792 if (ar.exception == null && ar.result != null) {
793 cellScanResult = new CellNetworkScanResult(
794 CellNetworkScanResult.STATUS_SUCCESS,
795 (List<OperatorInfo>) ar.result);
796 } else {
797 if (ar.result == null) {
798 loge("getCellNetworkScanResults: Empty response");
799 }
800 if (ar.exception != null) {
801 loge("getCellNetworkScanResults: Exception: " + ar.exception);
802 }
803 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
804 if (ar.exception instanceof CommandException) {
805 CommandException.Error error =
806 ((CommandException) (ar.exception)).getCommandError();
807 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
808 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
809 } else if (error == CommandException.Error.GENERIC_FAILURE) {
810 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
811 }
812 }
813 cellScanResult = new CellNetworkScanResult(errorCode, null);
814 }
815 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700816 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700817 break;
818
819 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
820 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700821 ManualNetworkSelectionArgument selArg =
822 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700823 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
824 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700825 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
826 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700827 break;
828
829 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700830 ar = (AsyncResult) msg.obj;
831 request = (MainThreadRequest) ar.userObj;
832 if (ar.exception == null) {
833 request.result = true;
834 } else {
835 request.result = false;
836 loge("setNetworkSelectionModeManual " + ar.exception);
837 }
838 notifyRequester(request);
839 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700840 break;
841
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700842 case CMD_GET_MODEM_ACTIVITY_INFO:
843 request = (MainThreadRequest) msg.obj;
844 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -0700845 if (defaultPhone != null) {
846 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
847 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700848 break;
849
850 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
851 ar = (AsyncResult) msg.obj;
852 request = (MainThreadRequest) ar.userObj;
853 if (ar.exception == null && ar.result != null) {
854 request.result = ar.result;
855 } else {
856 if (ar.result == null) {
857 loge("queryModemActivityInfo: Empty response");
858 } else if (ar.exception instanceof CommandException) {
859 loge("queryModemActivityInfo: CommandException: " +
860 ar.exception);
861 } else {
862 loge("queryModemActivityInfo: Unknown exception");
863 }
864 }
Amit Mahajand4766222016-01-28 15:28:28 -0800865 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
866 if (request.result == null) {
867 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
868 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700869 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700870 break;
871
Meng Wang1a7c35a2016-05-05 20:56:15 -0700872 case CMD_SET_ALLOWED_CARRIERS:
873 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -0800874 CarrierRestrictionRules argument =
875 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700876 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -0800877 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700878 break;
879
880 case EVENT_SET_ALLOWED_CARRIERS_DONE:
881 ar = (AsyncResult) msg.obj;
882 request = (MainThreadRequest) ar.userObj;
883 if (ar.exception == null && ar.result != null) {
884 request.result = ar.result;
885 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800886 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
887 if (ar.exception instanceof CommandException) {
888 loge("setAllowedCarriers: CommandException: " + ar.exception);
889 CommandException.Error error =
890 ((CommandException) (ar.exception)).getCommandError();
891 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
892 request.result =
893 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
894 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700895 } else {
896 loge("setAllowedCarriers: Unknown exception");
897 }
898 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700899 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700900 break;
901
902 case CMD_GET_ALLOWED_CARRIERS:
903 request = (MainThreadRequest) msg.obj;
904 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800905 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700906 break;
907
908 case EVENT_GET_ALLOWED_CARRIERS_DONE:
909 ar = (AsyncResult) msg.obj;
910 request = (MainThreadRequest) ar.userObj;
911 if (ar.exception == null && ar.result != null) {
912 request.result = ar.result;
913 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800914 request.result = new IllegalStateException(
915 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700916 if (ar.result == null) {
917 loge("getAllowedCarriers: Empty response");
918 } else if (ar.exception instanceof CommandException) {
919 loge("getAllowedCarriers: CommandException: " +
920 ar.exception);
921 } else {
922 loge("getAllowedCarriers: Unknown exception");
923 }
924 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700925 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700926 break;
927
Nathan Haroldb3014052017-01-25 15:57:32 -0800928 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
929 ar = (AsyncResult) msg.obj;
930 request = (MainThreadRequest) ar.userObj;
931 if (ar.exception == null && ar.result != null) {
932 request.result = ar.result;
933 } else {
934 request.result = new IllegalArgumentException(
935 "Failed to retrieve Forbidden Plmns");
936 if (ar.result == null) {
937 loge("getForbiddenPlmns: Empty response");
938 } else {
939 loge("getForbiddenPlmns: Unknown exception");
940 }
941 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700942 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800943 break;
944
945 case CMD_GET_FORBIDDEN_PLMNS:
946 request = (MainThreadRequest) msg.obj;
947 uiccCard = getUiccCardFromRequest(request);
948 if (uiccCard == null) {
949 loge("getForbiddenPlmns() UiccCard is null");
950 request.result = new IllegalArgumentException(
951 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700952 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800953 break;
954 }
955 Integer appType = (Integer) request.argument;
956 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
957 if (uiccApp == null) {
958 loge("getForbiddenPlmns() no app with specified type -- "
959 + appType);
960 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700961 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800962 break;
963 } else {
964 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
965 + " specified type -- " + appType);
966 }
967 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
968 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
969 onCompleted);
970 break;
971
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000972 case CMD_SWITCH_SLOTS:
973 request = (MainThreadRequest) msg.obj;
974 int[] physicalSlots = (int[]) request.argument;
975 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
976 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
977 break;
978
979 case EVENT_SWITCH_SLOTS_DONE:
980 ar = (AsyncResult) msg.obj;
981 request = (MainThreadRequest) ar.userObj;
982 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700983 notifyRequester(request);
984 break;
985 case CMD_GET_NETWORK_SELECTION_MODE:
986 request = (MainThreadRequest) msg.obj;
987 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
988 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
989 break;
990
991 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
992 ar = (AsyncResult) msg.obj;
993 request = (MainThreadRequest) ar.userObj;
994 if (ar.exception != null) {
995 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
996 } else {
997 int mode = ((int[]) ar.result)[0];
998 if (mode == 0) {
999 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1000 } else {
1001 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1002 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001003 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001004 notifyRequester(request);
1005 break;
1006 case CMD_GET_CDMA_ROAMING_MODE:
1007 request = (MainThreadRequest) msg.obj;
1008 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1009 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1010 break;
1011 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1012 ar = (AsyncResult) msg.obj;
1013 request = (MainThreadRequest) ar.userObj;
1014 if (ar.exception != null) {
1015 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1016 } else {
1017 request.result = ((int[]) ar.result)[0];
1018 }
1019 notifyRequester(request);
1020 break;
1021 case CMD_SET_CDMA_ROAMING_MODE:
1022 request = (MainThreadRequest) msg.obj;
1023 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1024 int mode = (int) request.argument;
1025 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1026 break;
1027 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1028 ar = (AsyncResult) msg.obj;
1029 request = (MainThreadRequest) ar.userObj;
1030 request.result = ar.exception == null;
1031 notifyRequester(request);
1032 break;
1033 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1034 request = (MainThreadRequest) msg.obj;
1035 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1036 int subscriptionMode = (int) request.argument;
1037 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1038 break;
1039 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1040 ar = (AsyncResult) msg.obj;
1041 request = (MainThreadRequest) ar.userObj;
1042 request.result = ar.exception == null;
1043 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001044 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001045 case CMD_GET_ALL_CELL_INFO:
1046 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001047 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001048 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001049 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001050 case EVENT_GET_ALL_CELL_INFO_DONE:
1051 ar = (AsyncResult) msg.obj;
1052 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001053 // If a timeout occurs, the response will be null
1054 request.result = (ar.exception == null && ar.result != null)
1055 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001056 synchronized (request) {
1057 request.notifyAll();
1058 }
1059 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001060 case CMD_REQUEST_CELL_INFO_UPDATE:
1061 request = (MainThreadRequest) msg.obj;
1062 request.phone.requestCellInfoUpdate(request.workSource,
1063 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1064 break;
1065 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1066 ar = (AsyncResult) msg.obj;
1067 request = (MainThreadRequest) ar.userObj;
1068 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1069 try {
1070 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001071 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Nathan Harolde82c4b82018-12-18 19:40:37 -08001072 cb.onError(TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1073 new android.os.ParcelableException(ar.exception));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001074 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001075 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Nathan Harolde82c4b82018-12-18 19:40:37 -08001076 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001077 } else {
1078 // use the result as returned
1079 cb.onCellInfo((List<CellInfo>) ar.result);
1080 }
1081 } catch (RemoteException re) {
1082 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1083 }
1084 break;
1085 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001086 request = (MainThreadRequest) msg.obj;
1087 WorkSource ws = (WorkSource) request.argument;
1088 Phone phone = getPhoneFromRequest(request);
1089 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1090 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001091 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001092 ar = (AsyncResult) msg.obj;
1093 request = (MainThreadRequest) ar.userObj;
1094 if (ar.exception == null) {
1095 request.result = ar.result;
1096 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001097 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001098 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1099 ? new CdmaCellLocation() : new GsmCellLocation();
1100 }
1101
1102 synchronized (request) {
1103 request.notifyAll();
1104 }
1105 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001106 case CMD_MODEM_REBOOT:
1107 request = (MainThreadRequest) msg.obj;
1108 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001109 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001110 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001111 case EVENT_CMD_MODEM_REBOOT_DONE:
1112 handleNullReturnEvent(msg, "rebootModem");
1113 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001114 case CMD_REQUEST_ENABLE_MODEM:
1115 request = (MainThreadRequest) msg.obj;
1116 boolean enable = (boolean) request.argument;
1117 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001118 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001119 PhoneConfigurationManager.getInstance()
1120 .enablePhone(request.phone, enable, onCompleted);
1121 break;
1122 case EVENT_ENABLE_MODEM_DONE:
1123 ar = (AsyncResult) msg.obj;
1124 request = (MainThreadRequest) ar.userObj;
1125 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001126 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001127 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001128 if ((boolean) request.result) {
1129 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1130 updateModemStateMetrics();
1131 } else {
1132 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1133 + ar.exception);
1134 }
1135 notifyRequester(request);
1136 break;
1137 case CMD_GET_MODEM_STATUS:
1138 request = (MainThreadRequest) msg.obj;
1139 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1140 PhoneConfigurationManager.getInstance()
1141 .getPhoneStatusFromModem(request.phone, onCompleted);
1142 break;
1143 case EVENT_GET_MODEM_STATUS_DONE:
1144 ar = (AsyncResult) msg.obj;
1145 request = (MainThreadRequest) ar.userObj;
1146 int id = request.phone.getPhoneId();
1147 if (ar.exception == null && ar.result != null) {
1148 request.result = ar.result;
1149 //update the cache as modem status has changed
1150 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1151 (boolean) request.result);
1152 } else {
1153 // Return true if modem status cannot be retrieved. For most cases,
1154 // modem status is on. And for older version modems, GET_MODEM_STATUS
1155 // and disable modem are not supported. Modem is always on.
1156 // TODO: this should be fixed in R to support a third
1157 // status UNKNOWN b/131631629
1158 request.result = true;
1159 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1160 + ar.exception);
1161 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001162 notifyRequester(request);
1163 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001164 default:
1165 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1166 break;
1167 }
1168 }
Jake Hambye994d462014-02-03 13:10:13 -08001169
Pengquan Menga1bb6272018-09-06 09:59:22 -07001170 private void notifyRequester(MainThreadRequest request) {
1171 synchronized (request) {
1172 request.notifyAll();
1173 }
1174 }
1175
Jake Hambye994d462014-02-03 13:10:13 -08001176 private void handleNullReturnEvent(Message msg, String command) {
1177 AsyncResult ar = (AsyncResult) msg.obj;
1178 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1179 if (ar.exception == null) {
1180 request.result = true;
1181 } else {
1182 request.result = false;
1183 if (ar.exception instanceof CommandException) {
1184 loge(command + ": CommandException: " + ar.exception);
1185 } else {
1186 loge(command + ": Unknown exception");
1187 }
1188 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001189 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001190 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001191 }
1192
1193 /**
1194 * Posts the specified command to be executed on the main thread,
1195 * waits for the request to complete, and returns the result.
1196 * @see #sendRequestAsync
1197 */
1198 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001199 return sendRequest(
1200 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001201 }
1202
1203 /**
1204 * Posts the specified command to be executed on the main thread,
1205 * waits for the request to complete, and returns the result.
1206 * @see #sendRequestAsync
1207 */
1208 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1209 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001210 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001211 }
1212
1213 /**
1214 * Posts the specified command to be executed on the main thread,
1215 * waits for the request to complete, and returns the result.
1216 * @see #sendRequestAsync
1217 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001218 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001219 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001220 }
1221
1222 /**
1223 * Posts the specified command to be executed on the main thread,
1224 * waits for the request to complete, and returns the result.
1225 * @see #sendRequestAsync
1226 */
Nathan Harold92bed182018-10-12 18:16:49 -07001227 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1228 return sendRequest(command, argument, subId, null, workSource);
1229 }
1230
1231 /**
1232 * Posts the specified command to be executed on the main thread,
1233 * waits for the request to complete, and returns the result.
1234 * @see #sendRequestAsync
1235 */
1236 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1237 return sendRequest(
1238 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1239 }
1240
1241 /**
1242 * Posts the specified command to be executed on the main thread,
1243 * waits for the request to complete, and returns the result.
1244 * @see #sendRequestAsync
1245 */
1246 private Object sendRequest(
1247 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001248 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1249 throw new RuntimeException("This method will deadlock if called from the main thread.");
1250 }
1251
Nathan Harold92bed182018-10-12 18:16:49 -07001252 MainThreadRequest request = null;
1253 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1254 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1255 } else if (phone != null) {
1256 request = new MainThreadRequest(argument, phone, workSource);
1257 } else {
1258 request = new MainThreadRequest(argument, subId, workSource);
1259 }
1260
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001261 Message msg = mMainThreadHandler.obtainMessage(command, request);
1262 msg.sendToTarget();
1263
1264 // Wait for the request to complete
1265 synchronized (request) {
1266 while (request.result == null) {
1267 try {
1268 request.wait();
1269 } catch (InterruptedException e) {
1270 // Do nothing, go back and wait until the request is complete
1271 }
1272 }
1273 }
1274 return request.result;
1275 }
1276
1277 /**
1278 * Asynchronous ("fire and forget") version of sendRequest():
1279 * Posts the specified command to be executed on the main thread, and
1280 * returns immediately.
1281 * @see #sendRequest
1282 */
1283 private void sendRequestAsync(int command) {
1284 mMainThreadHandler.sendEmptyMessage(command);
1285 }
1286
1287 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001288 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001289 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001290 */
1291 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001292 sendRequestAsync(command, argument, null, null);
1293 }
1294
1295 /**
1296 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1297 * @see {@link #sendRequest(int,Object)}
1298 */
1299 private void sendRequestAsync(
1300 int command, Object argument, Phone phone, WorkSource workSource) {
1301 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001302 Message msg = mMainThreadHandler.obtainMessage(command, request);
1303 msg.sendToTarget();
1304 }
1305
1306 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001307 * Initialize the singleton PhoneInterfaceManager instance.
1308 * This is only done once, at startup, from PhoneApp.onCreate().
1309 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001310 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001311 synchronized (PhoneInterfaceManager.class) {
1312 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001313 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001314 } else {
1315 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1316 }
1317 return sInstance;
1318 }
1319 }
1320
1321 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001322 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001323 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001324 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001325 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001326 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1327 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001328 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001329 mTelephonySharedPreferences =
1330 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001331 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001332 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001333
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001334 publish();
1335 }
1336
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001337 private Phone getDefaultPhone() {
1338 Phone thePhone = getPhone(getDefaultSubscription());
1339 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1340 }
1341
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001342 private void publish() {
1343 if (DBG) log("publish: " + this);
1344
1345 ServiceManager.addService("phone", this);
1346 }
1347
Stuart Scott584921c2015-01-15 17:10:34 -08001348 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001349 if (request.phone != null) {
1350 return request.phone;
1351 } else {
1352 return getPhoneFromSubId(request.subId);
1353 }
1354 }
1355
1356 private Phone getPhoneFromSubId(int subId) {
1357 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1358 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001359 }
1360
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001361 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1362 Phone phone = getPhoneFromRequest(request);
1363 return phone == null ? null :
1364 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1365 }
1366
Wink Saville36469e72014-06-11 15:17:00 -07001367 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001368 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001369 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001370 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001371
1372 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001373 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001374 }
1375
Wink Savilleb564aae2014-10-23 10:18:09 -07001376 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001377 if (DBG) log("dial: " + number);
1378 // No permission check needed here: This is just a wrapper around the
1379 // ACTION_DIAL intent, which is available to any app since it puts up
1380 // the UI before it does anything.
1381
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001382 final long identity = Binder.clearCallingIdentity();
1383 try {
1384 String url = createTelUrl(number);
1385 if (url == null) {
1386 return;
1387 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001388
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001389 // PENDING: should we just silently fail if phone is offhook or ringing?
1390 PhoneConstants.State state = mCM.getState(subId);
1391 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1392 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1393 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1394 mApp.startActivity(intent);
1395 }
1396 } finally {
1397 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001398 }
1399 }
1400
1401 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001402 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001403 }
1404
Wink Savilleb564aae2014-10-23 10:18:09 -07001405 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001406 if (DBG) log("call: " + number);
1407
1408 // This is just a wrapper around the ACTION_CALL intent, but we still
1409 // need to do a permission check since we're calling startActivity()
1410 // from the context of the phone app.
1411 enforceCallPermission();
1412
1413 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1414 != AppOpsManager.MODE_ALLOWED) {
1415 return;
1416 }
1417
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001418 final long identity = Binder.clearCallingIdentity();
1419 try {
1420 String url = createTelUrl(number);
1421 if (url == null) {
1422 return;
1423 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001424
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001425 boolean isValid = false;
1426 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1427 if (slist != null) {
1428 for (SubscriptionInfo subInfoRecord : slist) {
1429 if (subInfoRecord.getSubscriptionId() == subId) {
1430 isValid = true;
1431 break;
1432 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001433 }
Wink Saville08874612014-08-31 19:19:58 -07001434 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001435 if (!isValid) {
1436 return;
1437 }
Wink Saville08874612014-08-31 19:19:58 -07001438
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001439 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1440 intent.putExtra(SUBSCRIPTION_KEY, subId);
1441 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1442 mApp.startActivity(intent);
1443 } finally {
1444 Binder.restoreCallingIdentity(identity);
1445 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001446 }
1447
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001448 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001449 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001450 }
1451
Wink Savilleb564aae2014-10-23 10:18:09 -07001452 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001453 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001454 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1455 }
1456
1457 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001458 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001459 }
1460
Wink Savilleb564aae2014-10-23 10:18:09 -07001461 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001462 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001463 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1464 }
1465
1466 /** {@hide} */
1467 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001468 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001469 }
1470
Wink Savilleb564aae2014-10-23 10:18:09 -07001471 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001472 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001473
1474 final long identity = Binder.clearCallingIdentity();
1475 try {
1476 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1477 checkSimPin.start();
1478 return checkSimPin.unlockSim(null, pin);
1479 } finally {
1480 Binder.restoreCallingIdentity(identity);
1481 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001482 }
1483
Wink Saville9de0f752013-10-22 19:04:03 -07001484 /** {@hide} */
1485 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001486 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001487 }
1488
Wink Savilleb564aae2014-10-23 10:18:09 -07001489 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001490 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001491
1492 final long identity = Binder.clearCallingIdentity();
1493 try {
1494 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1495 checkSimPuk.start();
1496 return checkSimPuk.unlockSim(puk, pin);
1497 } finally {
1498 Binder.restoreCallingIdentity(identity);
1499 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001500 }
1501
1502 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001503 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001504 * a synchronous one.
1505 */
1506 private static class UnlockSim extends Thread {
1507
1508 private final IccCard mSimCard;
1509
1510 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001511 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1512 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001513
1514 // For replies from SimCard interface
1515 private Handler mHandler;
1516
1517 // For async handler to identify request type
1518 private static final int SUPPLY_PIN_COMPLETE = 100;
1519
1520 public UnlockSim(IccCard simCard) {
1521 mSimCard = simCard;
1522 }
1523
1524 @Override
1525 public void run() {
1526 Looper.prepare();
1527 synchronized (UnlockSim.this) {
1528 mHandler = new Handler() {
1529 @Override
1530 public void handleMessage(Message msg) {
1531 AsyncResult ar = (AsyncResult) msg.obj;
1532 switch (msg.what) {
1533 case SUPPLY_PIN_COMPLETE:
1534 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1535 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001536 mRetryCount = msg.arg1;
1537 if (ar.exception != null) {
1538 if (ar.exception instanceof CommandException &&
1539 ((CommandException)(ar.exception)).getCommandError()
1540 == CommandException.Error.PASSWORD_INCORRECT) {
1541 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1542 } else {
1543 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1544 }
1545 } else {
1546 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1547 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001548 mDone = true;
1549 UnlockSim.this.notifyAll();
1550 }
1551 break;
1552 }
1553 }
1554 };
1555 UnlockSim.this.notifyAll();
1556 }
1557 Looper.loop();
1558 }
1559
1560 /*
1561 * Use PIN or PUK to unlock SIM card
1562 *
1563 * If PUK is null, unlock SIM card with PIN
1564 *
1565 * If PUK is not null, unlock SIM card with PUK and set PIN code
1566 */
Wink Saville9de0f752013-10-22 19:04:03 -07001567 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001568
1569 while (mHandler == null) {
1570 try {
1571 wait();
1572 } catch (InterruptedException e) {
1573 Thread.currentThread().interrupt();
1574 }
1575 }
1576 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1577
1578 if (puk == null) {
1579 mSimCard.supplyPin(pin, callback);
1580 } else {
1581 mSimCard.supplyPuk(puk, pin, callback);
1582 }
1583
1584 while (!mDone) {
1585 try {
1586 Log.d(LOG_TAG, "wait for done");
1587 wait();
1588 } catch (InterruptedException e) {
1589 // Restore the interrupted status
1590 Thread.currentThread().interrupt();
1591 }
1592 }
1593 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001594 int[] resultArray = new int[2];
1595 resultArray[0] = mResult;
1596 resultArray[1] = mRetryCount;
1597 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001598 }
1599 }
1600
1601 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001602 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001603
1604 }
1605
Wink Savilleb564aae2014-10-23 10:18:09 -07001606 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001607 // No permission check needed here: this call is harmless, and it's
1608 // needed for the ServiceState.requestStateUpdate() call (which is
1609 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001610 final long identity = Binder.clearCallingIdentity();
1611 try {
1612 final Phone phone = getPhone(subId);
1613 if (phone != null) {
1614 phone.updateServiceLocation();
1615 }
1616 } finally {
1617 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001618 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001619 }
1620
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001621 @Override
1622 public boolean isRadioOn(String callingPackage) {
1623 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001624 }
1625
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001626 @Override
1627 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001628 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001629 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001630 return false;
1631 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001632
1633 final long identity = Binder.clearCallingIdentity();
1634 try {
1635 return isRadioOnForSubscriber(subId);
1636 } finally {
1637 Binder.restoreCallingIdentity(identity);
1638 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001639 }
1640
1641 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001642 final long identity = Binder.clearCallingIdentity();
1643 try {
1644 final Phone phone = getPhone(subId);
1645 if (phone != null) {
1646 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1647 } else {
1648 return false;
1649 }
1650 } finally {
1651 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001652 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001653 }
1654
1655 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001656 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001657 }
Wink Saville36469e72014-06-11 15:17:00 -07001658
Wink Savilleb564aae2014-10-23 10:18:09 -07001659 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001660 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001661
1662 final long identity = Binder.clearCallingIdentity();
1663 try {
1664 final Phone phone = getPhone(subId);
1665 if (phone != null) {
1666 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1667 }
1668 } finally {
1669 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001670 }
Wink Saville36469e72014-06-11 15:17:00 -07001671 }
1672
1673 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001674 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001675 }
1676
Wink Savilleb564aae2014-10-23 10:18:09 -07001677 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001678 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001679
1680 final long identity = Binder.clearCallingIdentity();
1681 try {
1682 final Phone phone = getPhone(subId);
1683 if (phone == null) {
1684 return false;
1685 }
1686 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1687 toggleRadioOnOffForSubscriber(subId);
1688 }
1689 return true;
1690 } finally {
1691 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001692 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001693 }
Wink Saville36469e72014-06-11 15:17:00 -07001694
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001695 public boolean needMobileRadioShutdown() {
1696 /*
1697 * If any of the Radios are available, it will need to be
1698 * shutdown. So return true if any Radio is available.
1699 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001700 final long identity = Binder.clearCallingIdentity();
1701 try {
1702 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1703 Phone phone = PhoneFactory.getPhone(i);
1704 if (phone != null && phone.isRadioAvailable()) return true;
1705 }
1706 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1707 return false;
1708 } finally {
1709 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001710 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001711 }
1712
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001713 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001714 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001715 enforceModifyPermission();
1716
1717 final long identity = Binder.clearCallingIdentity();
1718 try {
1719 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1720 logv("Shutting down Phone " + i);
1721 shutdownRadioUsingPhoneId(i);
1722 }
1723 } finally {
1724 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001725 }
1726 }
1727
1728 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001729 Phone phone = PhoneFactory.getPhone(phoneId);
1730 if (phone != null && phone.isRadioAvailable()) {
1731 phone.shutdownRadio();
1732 }
1733 }
1734
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001735 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001736 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001737
1738 final long identity = Binder.clearCallingIdentity();
1739 try {
1740 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1741 if (defaultPhone != null) {
1742 defaultPhone.setRadioPower(turnOn);
1743 return true;
1744 } else {
1745 loge("There's no default phone.");
1746 return false;
1747 }
1748 } finally {
1749 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001750 }
Wink Saville36469e72014-06-11 15:17:00 -07001751 }
1752
Wink Savilleb564aae2014-10-23 10:18:09 -07001753 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001754 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001755
1756 final long identity = Binder.clearCallingIdentity();
1757 try {
1758 final Phone phone = getPhone(subId);
1759 if (phone != null) {
1760 phone.setRadioPower(turnOn);
1761 return true;
1762 } else {
1763 return false;
1764 }
1765 } finally {
1766 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001767 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001768 }
1769
Wink Saville36469e72014-06-11 15:17:00 -07001770 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001771 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001772 public boolean enableDataConnectivity() {
1773 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001774
1775 final long identity = Binder.clearCallingIdentity();
1776 try {
1777 int subId = mSubscriptionController.getDefaultDataSubId();
1778 final Phone phone = getPhone(subId);
1779 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001780 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001781 return true;
1782 } else {
1783 return false;
1784 }
1785 } finally {
1786 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001787 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001788 }
1789
Wink Saville36469e72014-06-11 15:17:00 -07001790 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001791 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001792 public boolean disableDataConnectivity() {
1793 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001794
1795 final long identity = Binder.clearCallingIdentity();
1796 try {
1797 int subId = mSubscriptionController.getDefaultDataSubId();
1798 final Phone phone = getPhone(subId);
1799 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001800 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001801 return true;
1802 } else {
1803 return false;
1804 }
1805 } finally {
1806 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001807 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001808 }
1809
Sanket Padawe356d7632015-06-22 14:03:32 -07001810 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001811 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001812 final long identity = Binder.clearCallingIdentity();
1813 try {
1814 final Phone phone = getPhone(subId);
1815 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001816 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001817 } else {
1818 return false;
1819 }
1820 } finally {
1821 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001822 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001823 }
1824
1825 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001826 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001827 }
1828
pkanwarae03a6b2016-11-06 20:37:09 -08001829 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001830 enforceCallPermission();
1831
1832 final long identity = Binder.clearCallingIdentity();
1833 try {
1834 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1835 return;
1836 }
1837 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1838 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1839 } finally {
1840 Binder.restoreCallingIdentity(identity);
1841 }
pkanwar32d516d2016-10-14 19:37:38 -07001842 };
1843
Wink Savilleb564aae2014-10-23 10:18:09 -07001844 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001845 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001846
1847 final long identity = Binder.clearCallingIdentity();
1848 try {
1849 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1850 return false;
1851 }
1852 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1853 } finally {
1854 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001855 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001856 }
1857
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001858 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001859 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001860 }
1861
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001862 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001863 final long identity = Binder.clearCallingIdentity();
1864 try {
1865 Phone phone = PhoneFactory.getPhone(slotIndex);
1866 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1867 PhoneConstantConversions.convertCallState(phone.getState());
1868 } finally {
1869 Binder.restoreCallingIdentity(identity);
1870 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001871 }
1872
Sanket Padawe356d7632015-06-22 14:03:32 -07001873 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001874 public int getDataState() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001875 final long identity = Binder.clearCallingIdentity();
1876 try {
1877 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1878 if (phone != null) {
1879 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1880 } else {
1881 return PhoneConstantConversions.convertDataState(
1882 PhoneConstants.DataState.DISCONNECTED);
1883 }
1884 } finally {
1885 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001886 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001887 }
1888
Sanket Padawe356d7632015-06-22 14:03:32 -07001889 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001890 public int getDataActivity() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001891 final long identity = Binder.clearCallingIdentity();
1892 try {
1893 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1894 if (phone != null) {
1895 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1896 } else {
1897 return TelephonyManager.DATA_ACTIVITY_NONE;
1898 }
1899 } finally {
1900 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001901 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001902 }
1903
1904 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001905 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001906 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001907 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08001908
1909 LocationAccessPolicy.LocationPermissionResult locationResult =
1910 LocationAccessPolicy.checkLocationPermission(mApp,
1911 new LocationAccessPolicy.LocationPermissionQuery.Builder()
1912 .setCallingPackage(callingPackage)
1913 .setCallingPid(Binder.getCallingPid())
1914 .setCallingUid(Binder.getCallingUid())
1915 .setMethod("getCellLocation")
1916 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
1917 .build());
1918 switch (locationResult) {
1919 case DENIED_HARD:
1920 throw new SecurityException("Not allowed to access cell location");
1921 case DENIED_SOFT:
1922 return new Bundle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001923 }
1924
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001925 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001926 final long identity = Binder.clearCallingIdentity();
1927 try {
1928 if (DBG_LOC) log("getCellLocation: is active user");
1929 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001930 int subId = mSubscriptionController.getDefaultDataSubId();
1931 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1932 cl.fillInNotifierBundle(data);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001933 return data;
1934 } finally {
1935 Binder.restoreCallingIdentity(identity);
1936 }
Svetoslav64fad262015-04-14 14:35:21 -07001937 }
1938
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001939 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001940 public String getNetworkCountryIsoForPhone(int phoneId) {
1941 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1942 // registered cell info, so return a NULL country instead.
1943 final long identity = Binder.clearCallingIdentity();
1944 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001945 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1946 // Get default phone in this case.
1947 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1948 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001949 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001950 // Todo: fix this when we can get the actual cellular network info when the device
1951 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001952 if (TelephonyManager.NETWORK_TYPE_IWLAN
1953 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1954 return "";
1955 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001956 Phone phone = PhoneFactory.getPhone(phoneId);
1957 if (phone != null) {
1958 ServiceStateTracker sst = phone.getServiceStateTracker();
1959 if (sst != null) {
1960 LocaleTracker lt = sst.getLocaleTracker();
1961 if (lt != null) {
1962 return lt.getCurrentCountry();
1963 }
1964 }
1965 }
1966 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001967 } finally {
1968 Binder.restoreCallingIdentity(identity);
1969 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001970 }
1971
1972 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001973 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001974 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001975 }
1976
Sanket Padawe356d7632015-06-22 14:03:32 -07001977 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001978 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001979 mApp.enforceCallingOrSelfPermission(
1980 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001981
1982 final long identity = Binder.clearCallingIdentity();
1983 try {
1984 final Phone phone = getPhone(subId);
1985 if (phone != null) {
1986 phone.enableLocationUpdates();
1987 }
1988 } finally {
1989 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001990 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001991 }
1992
1993 @Override
1994 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001995 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001996 }
1997
Sanket Padawe356d7632015-06-22 14:03:32 -07001998 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001999 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002000 mApp.enforceCallingOrSelfPermission(
2001 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002002
2003 final long identity = Binder.clearCallingIdentity();
2004 try {
2005 final Phone phone = getPhone(subId);
2006 if (phone != null) {
2007 phone.disableLocationUpdates();
2008 }
2009 } finally {
2010 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002011 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002012 }
2013
Nathan Harold31d7ff32018-10-15 20:20:30 -07002014 /**
2015 * Returns the target SDK version number for a given package name.
2016 *
2017 * @return target SDK if the package is found or INT_MAX.
2018 */
2019 private int getTargetSdk(String packageName) {
2020 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002021 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(
2022 packageName, 0);
Nathan Harold31d7ff32018-10-15 20:20:30 -07002023 if (ai != null) return ai.targetSdkVersion;
2024 } catch (PackageManager.NameNotFoundException unexpected) {
2025 }
2026 return Integer.MAX_VALUE;
2027 }
2028
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002029 @Override
2030 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07002031 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
2032 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002033 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2034 throw new SecurityException(
2035 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2036 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002037
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002038 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
2039 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2040 return null;
2041 }
Svetoslav64fad262015-04-14 14:35:21 -07002042
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002043 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002044
Nathan Haroldf180aac2018-06-01 18:43:55 -07002045 List<CellInfo> info = getAllCellInfo(callingPackage);
2046 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002047
Nathan Haroldf180aac2018-06-01 18:43:55 -07002048 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2049 for (CellInfo ci : info) {
2050 if (ci instanceof CellInfoGsm) {
2051 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2052 } else if (ci instanceof CellInfoWcdma) {
2053 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2054 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002055 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002056 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002057 }
2058
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002059 private List<CellInfo> getCachedCellInfo() {
2060 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2061 for (Phone phone : PhoneFactory.getPhones()) {
2062 List<CellInfo> info = phone.getAllCellInfo();
2063 if (info != null) cellInfos.addAll(info);
2064 }
2065 return cellInfos;
2066 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002067
2068 @Override
Svetoslav64fad262015-04-14 14:35:21 -07002069 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002070 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002071 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002072
2073 LocationAccessPolicy.LocationPermissionResult locationResult =
2074 LocationAccessPolicy.checkLocationPermission(mApp,
2075 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2076 .setCallingPackage(callingPackage)
2077 .setCallingPid(Binder.getCallingPid())
2078 .setCallingUid(Binder.getCallingUid())
2079 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002080 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002081 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2082 .build());
2083 switch (locationResult) {
2084 case DENIED_HARD:
2085 throw new SecurityException("Not allowed to access cell info");
2086 case DENIED_SOFT:
2087 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002088 }
2089
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002090 final int targetSdk = getTargetSdk(callingPackage);
2091 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2092 return getCachedCellInfo();
2093 }
2094
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002095 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002096 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002097 final long identity = Binder.clearCallingIdentity();
2098 try {
2099 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2100 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002101 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002102 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002103 if (info != null) cellInfos.addAll(info);
2104 }
2105 return cellInfos;
2106 } finally {
2107 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002108 }
2109 }
2110
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002111 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002112 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2113 requestCellInfoUpdateInternal(
2114 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2115 }
2116
2117 @Override
2118 public void requestCellInfoUpdateWithWorkSource(
2119 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2120 enforceModifyPermission();
2121 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2122 }
2123
2124 private void requestCellInfoUpdateInternal(
2125 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002126 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002127 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002128
2129 LocationAccessPolicy.LocationPermissionResult locationResult =
2130 LocationAccessPolicy.checkLocationPermission(mApp,
2131 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2132 .setCallingPackage(callingPackage)
2133 .setCallingPid(Binder.getCallingPid())
2134 .setCallingUid(Binder.getCallingUid())
2135 .setMethod("requestCellInfoUpdate")
2136 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2137 .build());
2138 switch (locationResult) {
2139 case DENIED_HARD:
2140 throw new SecurityException("Not allowed to access cell info");
2141 case DENIED_SOFT:
2142 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002143 }
2144
2145 final Phone phone = getPhone(subId);
2146 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2147
2148 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2149 }
2150
2151 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002152 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002153 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002154 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002155
2156 final long identity = Binder.clearCallingIdentity();
2157 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002158 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002159 } finally {
2160 Binder.restoreCallingIdentity(identity);
2161 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002162 }
2163
Shishir Agrawala9f32182016-04-12 12:00:16 -07002164 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002165 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002166 Phone phone = PhoneFactory.getPhone(slotIndex);
2167 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002168 return null;
2169 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002170 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002171 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2172 callingPackage, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002173 return null;
2174 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002175
2176 final long identity = Binder.clearCallingIdentity();
2177 try {
2178 return phone.getImei();
2179 } finally {
2180 Binder.restoreCallingIdentity(identity);
2181 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002182 }
2183
2184 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002185 public String getTypeAllocationCodeForSlot(int slotIndex) {
2186 Phone phone = PhoneFactory.getPhone(slotIndex);
2187 String tac = null;
2188 if (phone != null) {
2189 String imei = phone.getImei();
2190 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2191 }
2192 return tac;
2193 }
2194
2195 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002196 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002197 Phone phone = PhoneFactory.getPhone(slotIndex);
2198 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002199 return null;
2200 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002201
Jeff Davidson913390f2018-02-23 17:11:49 -08002202 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002203 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2204 callingPackage, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002205 return null;
2206 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002207
2208 final long identity = Binder.clearCallingIdentity();
2209 try {
2210 return phone.getMeid();
2211 } finally {
2212 Binder.restoreCallingIdentity(identity);
2213 }
Jack Yu2af8d712017-03-15 17:14:14 -07002214 }
2215
2216 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002217 public String getManufacturerCodeForSlot(int slotIndex) {
2218 Phone phone = PhoneFactory.getPhone(slotIndex);
2219 String manufacturerCode = null;
2220 if (phone != null) {
2221 String meid = phone.getMeid();
2222 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2223 }
2224 return manufacturerCode;
2225 }
2226
2227 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002228 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002229 Phone phone = PhoneFactory.getPhone(slotIndex);
2230 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002231 return null;
2232 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002233 int subId = phone.getSubId();
2234 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2235 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2236 return null;
2237 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002238
2239 final long identity = Binder.clearCallingIdentity();
2240 try {
2241 return phone.getDeviceSvn();
2242 } finally {
2243 Binder.restoreCallingIdentity(identity);
2244 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002245 }
2246
fionaxu43304da2017-11-27 22:51:16 -08002247 @Override
2248 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002249 final long identity = Binder.clearCallingIdentity();
2250 try {
2251 final Phone phone = getPhone(subId);
2252 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2253 } finally {
2254 Binder.restoreCallingIdentity(identity);
2255 }
fionaxu43304da2017-11-27 22:51:16 -08002256 }
2257
2258 @Override
2259 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002260 final long identity = Binder.clearCallingIdentity();
2261 try {
2262 final Phone phone = getPhone(subId);
2263 return phone == null ? null : phone.getCarrierName();
2264 } finally {
2265 Binder.restoreCallingIdentity(identity);
2266 }
fionaxu43304da2017-11-27 22:51:16 -08002267 }
2268
calvinpanffe225e2018-11-01 19:43:06 +08002269 @Override
chen xu0026ca62019-03-06 15:28:50 -08002270 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002271 final long identity = Binder.clearCallingIdentity();
2272 try {
2273 final Phone phone = getPhone(subId);
2274 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002275 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002276 } finally {
2277 Binder.restoreCallingIdentity(identity);
2278 }
2279 }
2280
2281 @Override
chen xu0026ca62019-03-06 15:28:50 -08002282 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002283 final long identity = Binder.clearCallingIdentity();
2284 try {
2285 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002286 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002287 } finally {
2288 Binder.restoreCallingIdentity(identity);
2289 }
2290 }
2291
chen xu651eec72018-11-11 19:03:44 -08002292 @Override
chen xu864e11c2018-12-06 22:10:03 -08002293 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2294 if (!isSubscriptionMccMnc) {
2295 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2296 }
chen xu651eec72018-11-11 19:03:44 -08002297 final Phone phone = PhoneFactory.getPhone(slotIndex);
2298 if (phone == null) {
2299 return TelephonyManager.UNKNOWN_CARRIER_ID;
2300 }
2301 final long identity = Binder.clearCallingIdentity();
2302 try {
2303 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2304 } finally {
2305 Binder.restoreCallingIdentity(identity);
2306 }
2307 }
2308
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002309 //
2310 // Internal helper methods.
2311 //
2312
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002313 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002314 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2315 *
2316 * @throws SecurityException if the caller does not have the required permission
2317 */
2318 private void enforceModifyPermission() {
2319 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2320 }
2321
2322 /**
2323 * Make sure the caller has the CALL_PHONE permission.
2324 *
2325 * @throws SecurityException if the caller does not have the required permission
2326 */
2327 private void enforceCallPermission() {
2328 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2329 }
2330
Stuart Scott8eef64f2015-04-08 15:13:54 -07002331 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002332 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002333 "ConnectivityService");
2334 }
2335
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002336 private String createTelUrl(String number) {
2337 if (TextUtils.isEmpty(number)) {
2338 return null;
2339 }
2340
Jake Hambye994d462014-02-03 13:10:13 -08002341 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002342 }
2343
Ihab Awadf9e92732013-12-05 18:02:52 -08002344 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002345 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2346 }
2347
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002348 private static void logv(String msg) {
2349 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2350 }
2351
Ihab Awadf9e92732013-12-05 18:02:52 -08002352 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002353 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2354 }
2355
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002356 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002357 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002358 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002359 }
2360
Sanket Padawe356d7632015-06-22 14:03:32 -07002361 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002362 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002363 final long identity = Binder.clearCallingIdentity();
2364 try {
2365 final Phone phone = PhoneFactory.getPhone(slotIndex);
2366 if (phone == null) {
2367 return PhoneConstants.PHONE_TYPE_NONE;
2368 } else {
2369 return phone.getPhoneType();
2370 }
2371 } finally {
2372 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002373 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002374 }
2375
2376 /**
2377 * Returns the CDMA ERI icon index to display
2378 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002379 @Override
2380 public int getCdmaEriIconIndex(String callingPackage) {
2381 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002382 }
2383
Sanket Padawe356d7632015-06-22 14:03:32 -07002384 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002385 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002386 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002387 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002388 return -1;
2389 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002390
2391 final long identity = Binder.clearCallingIdentity();
2392 try {
2393 final Phone phone = getPhone(subId);
2394 if (phone != null) {
2395 return phone.getCdmaEriIconIndex();
2396 } else {
2397 return -1;
2398 }
2399 } finally {
2400 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002401 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002402 }
2403
2404 /**
2405 * Returns the CDMA ERI icon mode,
2406 * 0 - ON
2407 * 1 - FLASHING
2408 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002409 @Override
2410 public int getCdmaEriIconMode(String callingPackage) {
2411 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002412 }
2413
Sanket Padawe356d7632015-06-22 14:03:32 -07002414 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002415 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002416 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002417 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002418 return -1;
2419 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002420
2421 final long identity = Binder.clearCallingIdentity();
2422 try {
2423 final Phone phone = getPhone(subId);
2424 if (phone != null) {
2425 return phone.getCdmaEriIconMode();
2426 } else {
2427 return -1;
2428 }
2429 } finally {
2430 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002431 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002432 }
2433
2434 /**
2435 * Returns the CDMA ERI text,
2436 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002437 @Override
2438 public String getCdmaEriText(String callingPackage) {
2439 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002440 }
2441
Sanket Padawe356d7632015-06-22 14:03:32 -07002442 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002443 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002444 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002445 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002446 return null;
2447 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002448
2449 final long identity = Binder.clearCallingIdentity();
2450 try {
2451 final Phone phone = getPhone(subId);
2452 if (phone != null) {
2453 return phone.getCdmaEriText();
2454 } else {
2455 return null;
2456 }
2457 } finally {
2458 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002459 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002460 }
2461
2462 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002463 * Returns the CDMA MDN.
2464 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002465 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002466 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002467 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2468 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002469
2470 final long identity = Binder.clearCallingIdentity();
2471 try {
2472 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002473 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002474 return phone.getLine1Number();
2475 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002476 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002477 return null;
2478 }
2479 } finally {
2480 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002481 }
2482 }
2483
2484 /**
2485 * Returns the CDMA MIN.
2486 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002487 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002488 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002489 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2490 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002491
2492 final long identity = Binder.clearCallingIdentity();
2493 try {
2494 final Phone phone = getPhone(subId);
2495 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2496 return phone.getCdmaMin();
2497 } else {
2498 return null;
2499 }
2500 } finally {
2501 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002502 }
2503 }
2504
Hall Liud892bec2018-11-30 14:51:45 -08002505 @Override
2506 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2507 INumberVerificationCallback callback, String callingPackage) {
2508 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2509 != PERMISSION_GRANTED) {
2510 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2511 }
2512 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2513
2514 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2515 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2516 throw new SecurityException("Calling package must be configured in the device config");
2517 }
2518
2519 if (range == null) {
2520 throw new NullPointerException("Range must be non-null");
2521 }
2522
2523 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002524 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002525
2526 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2527 }
2528
Junda Liuca05d5d2014-08-14 22:36:34 -07002529 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002530 * Returns true if CDMA provisioning needs to run.
2531 */
2532 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002533 final long identity = Binder.clearCallingIdentity();
2534 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002535 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002536 } finally {
2537 Binder.restoreCallingIdentity(identity);
2538 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002539 }
2540
2541 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002542 * Sets the voice mail number of a given subId.
2543 */
2544 @Override
2545 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002546 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002547
2548 final long identity = Binder.clearCallingIdentity();
2549 try {
2550 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2551 new Pair<String, String>(alphaTag, number), new Integer(subId));
2552 return success;
2553 } finally {
2554 Binder.restoreCallingIdentity(identity);
2555 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002556 }
2557
Ta-wei Yen87c49842016-05-13 21:19:52 -07002558 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002559 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2560 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002561 String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002562 if (!TextUtils.equals(callingPackage, systemDialer)) {
2563 throw new SecurityException("caller must be system dialer");
2564 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002565
2566 final long identity = Binder.clearCallingIdentity();
2567 try {
2568 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2569 if (phoneAccountHandle == null) {
2570 return null;
2571 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002572 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002573 } finally {
2574 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002575 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002576 }
2577
2578 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002579 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002580 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002581 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002582 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002583 return null;
2584 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002585
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002586 final long identity = Binder.clearCallingIdentity();
2587 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002588 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002589 } finally {
2590 Binder.restoreCallingIdentity(identity);
2591 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002592 }
2593
2594 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002595 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2596 VisualVoicemailSmsFilterSettings settings) {
2597 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002598
2599 final long identity = Binder.clearCallingIdentity();
2600 try {
2601 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002602 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002603 } finally {
2604 Binder.restoreCallingIdentity(identity);
2605 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002606 }
2607
2608 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002609 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2610 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002611
2612 final long identity = Binder.clearCallingIdentity();
2613 try {
2614 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002615 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002616 } finally {
2617 Binder.restoreCallingIdentity(identity);
2618 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002619 }
2620
2621 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002622 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2623 String callingPackage, int subId) {
2624 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002625
2626 final long identity = Binder.clearCallingIdentity();
2627 try {
2628 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002629 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002630 } finally {
2631 Binder.restoreCallingIdentity(identity);
2632 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002633 }
2634
2635 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002636 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002637 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002638
2639 final long identity = Binder.clearCallingIdentity();
2640 try {
2641 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002642 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002643 } finally {
2644 Binder.restoreCallingIdentity(identity);
2645 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002646 }
2647
2648 @Override
2649 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2650 String number, int port, String text, PendingIntent sentIntent) {
2651 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002652 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002653 enforceSendSmsPermission();
2654 // Make the calls as the phone process.
2655 final long identity = Binder.clearCallingIdentity();
2656 try {
2657 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2658 if (port == 0) {
2659 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2660 sentIntent, null, false);
2661 } else {
2662 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2663 smsManager.sendDataMessageWithSelfPermissions(number, null,
2664 (short) port, data, sentIntent, null);
2665 }
2666 } finally {
2667 Binder.restoreCallingIdentity(identity);
2668 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002669 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002670 /**
fionaxu0152e512016-11-14 13:36:14 -08002671 * Sets the voice activation state of a given subId.
2672 */
2673 @Override
2674 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002675 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2676 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002677
2678 final long identity = Binder.clearCallingIdentity();
2679 try {
2680 final Phone phone = getPhone(subId);
2681 if (phone != null) {
2682 phone.setVoiceActivationState(activationState);
2683 } else {
2684 loge("setVoiceActivationState fails with invalid subId: " + subId);
2685 }
2686 } finally {
2687 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002688 }
2689 }
2690
2691 /**
2692 * Sets the data activation state of a given subId.
2693 */
2694 @Override
2695 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002696 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2697 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002698
2699 final long identity = Binder.clearCallingIdentity();
2700 try {
2701 final Phone phone = getPhone(subId);
2702 if (phone != null) {
2703 phone.setDataActivationState(activationState);
2704 } else {
2705 loge("setVoiceActivationState fails with invalid subId: " + subId);
2706 }
2707 } finally {
2708 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002709 }
2710 }
2711
2712 /**
2713 * Returns the voice activation state of a given subId.
2714 */
2715 @Override
2716 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002717 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002718
fionaxu0152e512016-11-14 13:36:14 -08002719 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002720 final long identity = Binder.clearCallingIdentity();
2721 try {
2722 if (phone != null) {
2723 return phone.getVoiceActivationState();
2724 } else {
2725 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2726 }
2727 } finally {
2728 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002729 }
2730 }
2731
2732 /**
2733 * Returns the data activation state of a given subId.
2734 */
2735 @Override
2736 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002737 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002738
fionaxu0152e512016-11-14 13:36:14 -08002739 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002740 final long identity = Binder.clearCallingIdentity();
2741 try {
2742 if (phone != null) {
2743 return phone.getDataActivationState();
2744 } else {
2745 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2746 }
2747 } finally {
2748 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002749 }
2750 }
2751
2752 /**
Wink Saville36469e72014-06-11 15:17:00 -07002753 * Returns the unread count of voicemails for a subId
2754 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002755 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002756 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2757 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2758 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2759 return 0;
2760 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002761 final long identity = Binder.clearCallingIdentity();
2762 try {
2763 final Phone phone = getPhone(subId);
2764 if (phone != null) {
2765 return phone.getVoiceMessageCount();
2766 } else {
2767 return 0;
2768 }
2769 } finally {
2770 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002771 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002772 }
2773
2774 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002775 * returns true, if the device is in a state where both voice and data
2776 * are supported simultaneously. This can change based on location or network condition.
2777 */
2778 @Override
2779 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002780 final long identity = Binder.clearCallingIdentity();
2781 try {
2782 final Phone phone = getPhone(subId);
2783 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2784 } finally {
2785 Binder.restoreCallingIdentity(identity);
2786 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002787 }
2788
2789 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002790 * Send the dialer code if called from the current default dialer or the caller has
2791 * carrier privilege.
2792 * @param inputCode The dialer code to send
2793 */
2794 @Override
2795 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002796 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002797 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002798 String defaultDialer = TelecomManager.from(defaultPhone.getContext())
2799 .getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002800 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002801 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2802 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002803 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002804
2805 final long identity = Binder.clearCallingIdentity();
2806 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002807 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002808 } finally {
2809 Binder.restoreCallingIdentity(identity);
2810 }
fionaxu235cc5e2017-03-06 22:25:57 -08002811 }
2812
2813 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002814 * Returns the data network type.
2815 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002816 *
2817 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2818 */
2819 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002820 public int getNetworkType() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002821 final long identity = Binder.clearCallingIdentity();
2822 try {
2823 final Phone phone = getPhone(getDefaultSubscription());
2824 if (phone != null) {
2825 return phone.getServiceState().getDataNetworkType();
2826 } else {
2827 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2828 }
2829 } finally {
2830 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002831 }
Wink Saville36469e72014-06-11 15:17:00 -07002832 }
2833
Pengquan Menga1bb6272018-09-06 09:59:22 -07002834 @Override
2835 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002836 if (!isActiveSubscription(subId)) {
2837 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2838 }
2839
Pengquan Menga1bb6272018-09-06 09:59:22 -07002840 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2841 }
2842
Brad Ebinger35c841c2018-10-01 10:40:55 -07002843 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002844 public boolean isInEmergencySmsMode() {
2845 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2846 final long identity = Binder.clearCallingIdentity();
2847 try {
2848 for (Phone phone : PhoneFactory.getPhones()) {
2849 if (phone.isInEmergencySmsMode()) {
2850 return true;
2851 }
2852 }
2853 } finally {
2854 Binder.restoreCallingIdentity(identity);
2855 }
2856 return false;
2857 }
2858
2859 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002860 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2861 throws RemoteException {
2862 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002863 final long token = Binder.clearCallingIdentity();
2864 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002865 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002866 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002867 .addRegistrationCallbackForSubscription(c, subId);
2868 } finally {
2869 Binder.restoreCallingIdentity(token);
2870 }
2871 }
2872
2873 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002874 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2875 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002876 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2877 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2878 }
2879 Binder.withCleanCallingIdentity(() -> {
2880 try {
2881 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002882 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002883 .removeRegistrationCallbackForSubscription(c, subId);
2884 } catch (IllegalArgumentException e) {
2885 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2886 + "is inactive, ignoring unregister.");
2887 // If the subscription is no longer active, just return, since the callback
2888 // will already have been removed internally.
2889 }
2890 });
Brad Ebinger35c841c2018-10-01 10:40:55 -07002891 }
2892
2893 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002894 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2895 throws RemoteException {
2896 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002897 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2898 final long token = Binder.clearCallingIdentity();
2899 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002900 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002901 .addCapabilitiesCallbackForSubscription(c, subId);
2902 } finally {
2903 Binder.restoreCallingIdentity(token);
2904 }
2905 }
2906
2907 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002908 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2909 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002910
2911 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2912 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2913 }
2914 Binder.withCleanCallingIdentity(() -> {
2915 try {
2916 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002917 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002918 .removeCapabilitiesCallbackForSubscription(c, subId);
2919 } catch (IllegalArgumentException e) {
2920 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
2921 + "is inactive, ignoring unregister.");
2922 // If the subscription is no longer active, just return, since the callback
2923 // will already have been removed internally.
2924 }
2925 });
Brad Ebinger35c841c2018-10-01 10:40:55 -07002926 }
2927
2928 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002929 public boolean isCapable(int subId, int capability, int regTech) {
2930 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002931 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2932 final long token = Binder.clearCallingIdentity();
2933 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002934 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002935 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2936 } catch (ImsException e) {
2937 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2938 return false;
Brad Ebinger6b5ac222019-02-04 14:36:52 -08002939 } catch (IllegalArgumentException e) {
2940 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
2941 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07002942 } finally {
2943 Binder.restoreCallingIdentity(token);
2944 }
2945 }
2946
2947 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002948 public boolean isAvailable(int subId, int capability, int regTech) {
2949 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002950 final long token = Binder.clearCallingIdentity();
2951 try {
2952 Phone phone = getPhone(subId);
2953 if (phone == null) return false;
2954 return phone.isImsCapabilityAvailable(capability, regTech);
2955 } finally {
2956 Binder.restoreCallingIdentity(token);
2957 }
2958 }
2959
2960 @Override
2961 public boolean isAdvancedCallingSettingEnabled(int subId) {
2962 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2963 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2964 final long token = Binder.clearCallingIdentity();
2965 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002966 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002967 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2968 } finally {
2969 Binder.restoreCallingIdentity(token);
2970 }
2971 }
2972
2973 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08002974 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002975 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08002976 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002977 final long identity = Binder.clearCallingIdentity();
2978 try {
2979 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002980 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002981 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2982 } finally {
2983 Binder.restoreCallingIdentity(identity);
2984 }
2985 }
2986
2987 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002988 public boolean isVtSettingEnabled(int subId) {
2989 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002990 final long identity = Binder.clearCallingIdentity();
2991 try {
2992 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002993 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002994 getSlotIndexOrException(subId)).isVtEnabledByUser();
2995 } finally {
2996 Binder.restoreCallingIdentity(identity);
2997 }
2998 }
2999
3000 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003001 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003002 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003003 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003004 final long identity = Binder.clearCallingIdentity();
3005 try {
3006 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003007 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003008 } finally {
3009 Binder.restoreCallingIdentity(identity);
3010 }
3011 }
3012
3013 @Override
3014 public boolean isVoWiFiSettingEnabled(int subId) {
3015 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3016 final long identity = Binder.clearCallingIdentity();
3017 try {
3018 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003019 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003020 getSlotIndexOrException(subId)).isWfcEnabledByUser();
3021 } finally {
3022 Binder.restoreCallingIdentity(identity);
3023 }
3024 }
3025
3026 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003027 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003028 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003029 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003030 final long identity = Binder.clearCallingIdentity();
3031 try {
3032 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003033 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003034 } finally {
3035 Binder.restoreCallingIdentity(identity);
3036 }
3037 }
3038
3039 @Override
3040 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3041 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3042 final long identity = Binder.clearCallingIdentity();
3043 try {
3044 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003045 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003046 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
3047 } finally {
3048 Binder.restoreCallingIdentity(identity);
3049 }
3050 }
3051
3052 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003053 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003054 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003055 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003056 final long identity = Binder.clearCallingIdentity();
3057 try {
3058 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003059 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003060 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
3061 } finally {
3062 Binder.restoreCallingIdentity(identity);
3063 }
3064 }
3065
3066 @Override
3067 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3068 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3069 "setVoWiFiNonPersistent");
3070 final long identity = Binder.clearCallingIdentity();
3071 try {
3072 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003073 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003074 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003075 } finally {
3076 Binder.restoreCallingIdentity(identity);
3077 }
3078 }
3079
3080 @Override
3081 public int getVoWiFiModeSetting(int subId) {
3082 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3083 final long identity = Binder.clearCallingIdentity();
3084 try {
3085 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003086 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003087 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
3088 } finally {
3089 Binder.restoreCallingIdentity(identity);
3090 }
3091 }
3092
3093 @Override
3094 public void setVoWiFiModeSetting(int subId, int mode) {
3095 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3096 "setVoWiFiModeSetting");
3097 final long identity = Binder.clearCallingIdentity();
3098 try {
3099 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003100 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003101 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
3102 } finally {
3103 Binder.restoreCallingIdentity(identity);
3104 }
3105 }
3106
3107 @Override
3108 public int getVoWiFiRoamingModeSetting(int subId) {
3109 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3110 final long identity = Binder.clearCallingIdentity();
3111 try {
3112 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003113 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003114 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
3115 } finally {
3116 Binder.restoreCallingIdentity(identity);
3117 }
3118 }
3119
3120 @Override
3121 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3122 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3123 "setVoWiFiRoamingModeSetting");
3124 final long identity = Binder.clearCallingIdentity();
3125 try {
3126 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003127 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003128 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
3129 } finally {
3130 Binder.restoreCallingIdentity(identity);
3131 }
3132 }
3133
3134 @Override
3135 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3136 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3137 "setRttCapabilityEnabled");
3138 final long identity = Binder.clearCallingIdentity();
3139 try {
3140 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003141 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003142 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3143 } finally {
3144 Binder.restoreCallingIdentity(identity);
3145 }
3146 }
3147
3148 @Override
3149 public boolean isTtyOverVolteEnabled(int subId) {
3150 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3151 final long identity = Binder.clearCallingIdentity();
3152 try {
3153 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003154 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003155 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
3156 } finally {
3157 Binder.restoreCallingIdentity(identity);
3158 }
3159 }
3160
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003161 @Override
3162 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3163 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3164 final long identity = Binder.clearCallingIdentity();
3165 try {
3166 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003167 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003168 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003169 } finally {
3170 Binder.restoreCallingIdentity(identity);
3171 }
3172 }
3173
3174 @Override
3175 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3176 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3177 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003178 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3179 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3180 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003181 try {
3182 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003183 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003184 .removeProvisioningCallbackForSubscription(callback, subId);
3185 } catch (IllegalArgumentException e) {
3186 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3187 + "is inactive, ignoring unregister.");
3188 // If the subscription is no longer active, just return, since the callback will already
3189 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003190 } finally {
3191 Binder.restoreCallingIdentity(identity);
3192 }
3193 }
3194
3195 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003196 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3197 boolean isProvisioned) {
3198 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3199 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3200 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3201 }
3202 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3203 "setProvisioningStatusForCapability");
3204 final long identity = Binder.clearCallingIdentity();
3205 try {
3206 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3207 Phone phone = getPhone(subId);
3208 if (phone == null) {
3209 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3210 + subId);
3211 return;
3212 }
3213 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3214 return;
3215 }
3216
3217 // this capability requires provisioning, route to the correct API.
3218 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3219 switch (capability) {
3220 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3221 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3222 ims.setVolteProvisioned(isProvisioned);
3223 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3224 ims.setWfcProvisioned(isProvisioned);
3225 }
3226 break;
3227 }
3228 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3229 // There is currently no difference in VT provisioning type.
3230 ims.setVtProvisioned(isProvisioned);
3231 break;
3232 }
3233 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3234 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3235 // change the capability of the feature instead if needed.
3236 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3237 == isProvisioned) {
3238 // No change in provisioning.
3239 return;
3240 }
3241 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3242 try {
3243 ims.changeMmTelCapability(capability, tech, isProvisioned);
3244 } catch (ImsException e) {
3245 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3246 + ", Exception" + e.getMessage());
3247 }
3248 break;
3249 }
3250 default: {
3251 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3252 + capability + "', which does not require provisioning.");
3253 }
3254 }
3255
3256 } finally {
3257 Binder.restoreCallingIdentity(identity);
3258 }
3259 }
3260
3261 @Override
3262 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3263 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3264 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3265 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3266 }
3267 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3268 final long identity = Binder.clearCallingIdentity();
3269 try {
3270 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3271 Phone phone = getPhone(subId);
3272 if (phone == null) {
3273 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3274 + subId);
3275 // We will fail with "true" as the provisioning status because this is the default
3276 // if we do not require provisioning.
3277 return true;
3278 }
3279
3280 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3281 return true;
3282 }
3283
3284 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3285 switch (capability) {
3286 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3287 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3288 return ims.isVolteProvisionedOnDevice();
3289 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3290 return ims.isWfcProvisionedOnDevice();
3291 }
3292 // This should never happen, since we are checking tech above to make sure it
3293 // is either LTE or IWLAN.
3294 throw new IllegalArgumentException("Invalid radio technology for voice "
3295 + "capability.");
3296 }
3297 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3298 // There is currently no difference in VT provisioning type.
3299 return ims.isVtProvisionedOnDevice();
3300 }
3301 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3302 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3303 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3304 }
3305 default: {
3306 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3307 + capability + "', which does not require provisioning.");
3308 }
3309 }
3310
3311 } finally {
3312 Binder.restoreCallingIdentity(identity);
3313 }
3314 }
3315
3316 @Override
3317 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3318 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3319 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3320 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3321 }
3322 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3323 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3324 return (provisionedBits & capability) > 0;
3325 }
3326
3327 @Override
3328 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3329 boolean isProvisioned) {
3330 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3331 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3332 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3333 }
3334 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3335 "setProvisioningStatusForCapability");
3336 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3337 // If the current provisioning status for capability already matches isProvisioned,
3338 // do nothing.
3339 if (((provisionedBits & capability) > 0) == isProvisioned) {
3340 return;
3341 }
3342 if (isProvisioned) {
3343 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3344 } else {
3345 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3346 }
3347 }
3348
3349 /**
3350 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3351 * technology. The bitfield should mirror the bitfield defined by
3352 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3353 */
3354 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3355 String key = getMmTelProvisioningKey(subId, tech);
3356 // Default is no capabilities are provisioned.
3357 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3358 }
3359
3360 /**
3361 * Sets the MmTel capability provisioning bitfield (defined by
3362 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3363 * technology specified.
3364 *
3365 * Note: This is a synchronous command and should not be called on UI thread.
3366 */
3367 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3368 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3369 String key = getMmTelProvisioningKey(subId, tech);
3370 editor.putInt(key, newField);
3371 editor.commit();
3372 }
3373
3374 private static String getMmTelProvisioningKey(int subId, int tech) {
3375 // resulting key is provision_ims_mmtel_{subId}_{tech}
3376 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3377 }
3378
3379 /**
3380 * Query CarrierConfig to see if the specified capability requires provisioning for the
3381 * carrier associated with the subscription id.
3382 */
3383 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3384 int capability) {
3385 CarrierConfigManager configManager = new CarrierConfigManager(context);
3386 PersistableBundle c = configManager.getConfigForSubId(subId);
3387 boolean requireUtProvisioning = c.getBoolean(
3388 // By default, this config is true (even if there is no SIM). We also check to make
3389 // sure the subscription needs provisioning here, so we do not need to check for
3390 // the no-SIM case, where we would normally shortcut this to false.
3391 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, true)
3392 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3393 false);
3394 boolean requireVoiceVtProvisioning = c.getBoolean(
3395 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3396
3397 // First check to make sure that the capability requires provisioning.
3398 switch (capability) {
3399 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3400 // intentional fallthrough
3401 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3402 if (requireVoiceVtProvisioning) {
3403 // Voice and Video requires provisioning
3404 return true;
3405 }
3406 break;
3407 }
3408 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3409 if (requireUtProvisioning) {
3410 // UT requires provisioning
3411 return true;
3412 }
3413 break;
3414 }
3415 }
3416 return false;
3417 }
3418
3419 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003420 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003421 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3422 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3423 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003424 enforceReadPrivilegedPermission("getImsProvisioningInt");
3425 final long identity = Binder.clearCallingIdentity();
3426 try {
3427 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003428 int slotId = getSlotIndex(subId);
3429 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3430 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3431 + subId + "' for key:" + key);
3432 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3433 }
3434 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003435 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003436 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3437 + subId + "' for key:" + key);
3438 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003439 } finally {
3440 Binder.restoreCallingIdentity(identity);
3441 }
3442 }
3443
3444 @Override
3445 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003446 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3447 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3448 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003449 enforceReadPrivilegedPermission("getImsProvisioningString");
3450 final long identity = Binder.clearCallingIdentity();
3451 try {
3452 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003453 int slotId = getSlotIndex(subId);
3454 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3455 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3456 + subId + "' for key:" + key);
3457 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3458 }
3459 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003460 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003461 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3462 + subId + "' for key:" + key);
3463 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003464 } finally {
3465 Binder.restoreCallingIdentity(identity);
3466 }
3467 }
3468
3469 @Override
3470 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003471 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3472 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3473 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003474 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3475 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003476 final long identity = Binder.clearCallingIdentity();
3477 try {
3478 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003479 int slotId = getSlotIndex(subId);
3480 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3481 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3482 + subId + "' for key:" + key);
3483 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3484 }
3485 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003486 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003487 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3488 + "' for key:" + key);
3489 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003490 } finally {
3491 Binder.restoreCallingIdentity(identity);
3492 }
3493 }
3494
3495 @Override
3496 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003497 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3498 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3499 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003500 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3501 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003502 final long identity = Binder.clearCallingIdentity();
3503 try {
3504 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003505 int slotId = getSlotIndex(subId);
3506 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3507 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3508 + subId + "' for key:" + key);
3509 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3510 }
3511 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003512 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003513 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3514 + "' for key:" + key);
3515 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003516 } finally {
3517 Binder.restoreCallingIdentity(identity);
3518 }
3519 }
3520
Brad Ebinger35c841c2018-10-01 10:40:55 -07003521 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
3522 int slotId = SubscriptionManager.getSlotIndex(subId);
3523 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003524 throw new IllegalArgumentException("Invalid Subscription Id, subId=" + subId);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003525 }
3526 return slotId;
3527 }
3528
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003529 private int getSlotIndex(int subId) {
3530 int slotId = SubscriptionManager.getSlotIndex(subId);
3531 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3532 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3533 }
3534 return slotId;
3535 }
3536
Wink Saville36469e72014-06-11 15:17:00 -07003537 /**
3538 * Returns the network type for a subId
3539 */
3540 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003541 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003542 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003543 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003544 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3545 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003546
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003547 final long identity = Binder.clearCallingIdentity();
3548 try {
3549 final Phone phone = getPhone(subId);
3550 if (phone != null) {
3551 return phone.getServiceState().getDataNetworkType();
3552 } else {
3553 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3554 }
3555 } finally {
3556 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003557 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003558 }
3559
3560 /**
3561 * Returns the data network type
3562 */
3563 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003564 public int getDataNetworkType(String callingPackage) {
3565 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003566 }
3567
3568 /**
3569 * Returns the data network type for a subId
3570 */
3571 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003572 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003573 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003574 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003575 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3576 }
3577
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003578 final long identity = Binder.clearCallingIdentity();
3579 try {
3580 final Phone phone = getPhone(subId);
3581 if (phone != null) {
3582 return phone.getServiceState().getDataNetworkType();
3583 } else {
3584 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3585 }
3586 } finally {
3587 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003588 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003589 }
3590
3591 /**
Wink Saville36469e72014-06-11 15:17:00 -07003592 * Returns the Voice network type for a subId
3593 */
3594 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003595 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003596 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003597 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003598 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3599 }
3600
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003601 final long identity = Binder.clearCallingIdentity();
3602 try {
3603 final Phone phone = getPhone(subId);
3604 if (phone != null) {
3605 return phone.getServiceState().getVoiceNetworkType();
3606 } else {
3607 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3608 }
3609 } finally {
3610 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003611 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003612 }
3613
3614 /**
3615 * @return true if a ICC card is present
3616 */
3617 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003618 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003619 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3620 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003621 }
3622
3623 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003624 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003625 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003626 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003627 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003628 final long identity = Binder.clearCallingIdentity();
3629 try {
3630 final Phone phone = PhoneFactory.getPhone(slotIndex);
3631 if (phone != null) {
3632 return phone.getIccCard().hasIccCard();
3633 } else {
3634 return false;
3635 }
3636 } finally {
3637 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003638 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003639 }
3640
3641 /**
3642 * Return if the current radio is LTE on CDMA. This
3643 * is a tri-state return value as for a period of time
3644 * the mode may be unknown.
3645 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003646 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003647 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003648 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003649 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003650 @Override
3651 public int getLteOnCdmaMode(String callingPackage) {
3652 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003653 }
3654
Sanket Padawe356d7632015-06-22 14:03:32 -07003655 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003656 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003657 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003658 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003659 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3660 }
3661
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003662 final long identity = Binder.clearCallingIdentity();
3663 try {
3664 final Phone phone = getPhone(subId);
3665 if (phone == null) {
3666 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3667 } else {
3668 return phone.getLteOnCdmaMode();
3669 }
3670 } finally {
3671 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003672 }
Wink Saville36469e72014-06-11 15:17:00 -07003673 }
3674
Wink Saville36469e72014-06-11 15:17:00 -07003675 /**
3676 * {@hide}
3677 * Returns Default subId, 0 in the case of single standby.
3678 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003679 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003680 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003681 }
3682
Shishir Agrawala9f32182016-04-12 12:00:16 -07003683 private int getSlotForDefaultSubscription() {
3684 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3685 }
3686
Wink Savilleb564aae2014-10-23 10:18:09 -07003687 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003688 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003689 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003690
Pengquan Menge92a50d2018-09-21 15:54:48 -07003691 private boolean isActiveSubscription(int subId) {
3692 return mSubscriptionController.isActiveSubId(subId);
3693 }
3694
Ihab Awadf2177b72013-11-25 13:33:23 -08003695 /**
3696 * @see android.telephony.TelephonyManager.WifiCallingChoices
3697 */
3698 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003699 final long identity = Binder.clearCallingIdentity();
3700 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003701 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003702 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3703 getWhenToMakeWifiCallsDefaultPreference());
3704 } finally {
3705 Binder.restoreCallingIdentity(identity);
3706 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003707 }
3708
3709 /**
3710 * @see android.telephony.TelephonyManager.WifiCallingChoices
3711 */
3712 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003713 final long identity = Binder.clearCallingIdentity();
3714 try {
3715 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003716 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003717 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3718 } finally {
3719 Binder.restoreCallingIdentity(identity);
3720 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003721 }
3722
Sailesh Nepald1e68152013-12-12 19:08:02 -08003723 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003724 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003725 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003726 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003727
Jordan Liu4c733742019-02-28 12:03:40 -08003728 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
3729 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
3730 if (phoneId == -1) {
3731 throw new IllegalArgumentException("Given slot index: " + slotIndex
3732 + " does not correspond to an active phone");
3733 }
3734 return PhoneFactory.getPhone(phoneId);
3735 }
3736
Shishir Agrawal566b7612013-10-28 14:41:00 -07003737 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003738 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3739 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003740 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3741 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003742 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08003743 if (DBG) {
3744 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3745 }
3746 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
3747 p2);
3748 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003749
Jordan Liu4c733742019-02-28 12:03:40 -08003750
3751 @Override
3752 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
3753 int slotIndex, String callingPackage, String aid, int p2) {
3754 enforceModifyPermission();
3755 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3756 if (DBG) {
3757 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
3758 }
3759 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3760 callingPackage, aid, p2);
3761 }
3762
3763 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
3764 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003765 final long identity = Binder.clearCallingIdentity();
3766 try {
3767 if (TextUtils.equals(ISDR_AID, aid)) {
3768 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003769 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3770 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003771 if (bestComponent == null
3772 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3773 loge("The calling package is not allowed to access ISD-R.");
3774 throw new SecurityException(
3775 "The calling package is not allowed to access ISD-R.");
3776 }
Derek Tan740e1672017-06-27 14:56:27 -07003777 }
Derek Tan740e1672017-06-27 14:56:27 -07003778
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003779 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08003780 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
3781 null /* workSource */);
3782 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003783 return response;
3784 } finally {
3785 Binder.restoreCallingIdentity(identity);
3786 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003787 }
3788
3789 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003790 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003791 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3792 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08003793 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3794 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
3795 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003796
Jordan Liu4c733742019-02-28 12:03:40 -08003797 @Override
3798 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
3799 enforceModifyPermission();
3800 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
3801 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3802 channel);
3803 }
3804
3805 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003806 final long identity = Binder.clearCallingIdentity();
3807 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003808 if (channel < 0) {
3809 return false;
3810 }
Jordan Liu4c733742019-02-28 12:03:40 -08003811 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
3812 null /* workSource */);
3813 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003814 return success;
3815 } finally {
3816 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003817 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003818 }
3819
3820 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003821 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003822 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003823 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3824 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08003825 if (DBG) {
3826 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3827 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3828 + p3 + " data=" + data);
3829 }
3830 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
3831 command, p1, p2, p3, data);
3832 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003833
Jordan Liu4c733742019-02-28 12:03:40 -08003834 @Override
3835 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
3836 int command, int p1, int p2, int p3, String data) {
3837 enforceModifyPermission();
3838 if (DBG) {
3839 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
3840 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3841 + p3 + " data=" + data);
3842 }
3843 return iccTransmitApduLogicalChannelWithPermission(
3844 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
3845 data);
3846 }
3847
3848 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
3849 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003850 final long identity = Binder.clearCallingIdentity();
3851 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003852 if (channel < 0) {
3853 return "";
3854 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003855
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003856 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08003857 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
3858 null /* workSource */);
3859 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003860
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003861 // Append the returned status code to the end of the response payload.
3862 String s = Integer.toHexString(
3863 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3864 if (response.payload != null) {
3865 s = IccUtils.bytesToHexString(response.payload) + s;
3866 }
3867 return s;
3868 } finally {
3869 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003870 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003871 }
Jake Hambye994d462014-02-03 13:10:13 -08003872
Evan Charltonc66da362014-05-16 14:06:40 -07003873 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003874 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3875 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003876 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3877 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003878 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08003879 if (DBG) {
3880 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3881 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3882 }
3883 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
3884 cla, command, p1, p2, p3, data);
3885 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003886
Jordan Liu4c733742019-02-28 12:03:40 -08003887 @Override
3888 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
3889 int command, int p1, int p2, int p3, String data) {
3890 enforceModifyPermission();
3891 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3892 if (DBG) {
3893 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
3894 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
3895 + " data=" + data);
3896 }
3897
3898 return iccTransmitApduBasicChannelWithPermission(
3899 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
3900 p2, p3, data);
3901 }
3902
3903 // open APDU basic channel assuming the caller has sufficient permissions
3904 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
3905 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003906 final long identity = Binder.clearCallingIdentity();
3907 try {
3908 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3909 && TextUtils.equals(ISDR_AID, data)) {
3910 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003911 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3912 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003913 if (bestComponent == null
3914 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3915 loge("The calling package is not allowed to select ISD-R.");
3916 throw new SecurityException(
3917 "The calling package is not allowed to select ISD-R.");
3918 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003919 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003920
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003921 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08003922 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
3923 null /* workSource */);
3924 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003925
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003926 // Append the returned status code to the end of the response payload.
3927 String s = Integer.toHexString(
3928 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3929 if (response.payload != null) {
3930 s = IccUtils.bytesToHexString(response.payload) + s;
3931 }
3932 return s;
3933 } finally {
3934 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003935 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003936 }
3937
3938 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003939 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003940 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003941 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3942 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003943
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003944 final long identity = Binder.clearCallingIdentity();
3945 try {
3946 if (DBG) {
3947 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3948 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3949 }
3950
3951 IccIoResult response =
3952 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3953 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3954 subId);
3955
3956 if (DBG) {
3957 log("Exchange SIM_IO [R]" + response);
3958 }
3959
3960 byte[] result = null;
3961 int length = 2;
3962 if (response.payload != null) {
3963 length = 2 + response.payload.length;
3964 result = new byte[length];
3965 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3966 } else {
3967 result = new byte[length];
3968 }
3969
3970 result[length - 1] = (byte) response.sw2;
3971 result[length - 2] = (byte) response.sw1;
3972 return result;
3973 } finally {
3974 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003975 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003976 }
3977
Nathan Haroldb3014052017-01-25 15:57:32 -08003978 /**
3979 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3980 * on a particular subscription
3981 */
sqianb6e41952018-03-12 14:54:01 -07003982 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3983 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3984 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3985 return null;
3986 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003987
3988 final long identity = Binder.clearCallingIdentity();
3989 try {
3990 if (appType != TelephonyManager.APPTYPE_USIM
3991 && appType != TelephonyManager.APPTYPE_SIM) {
3992 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3993 return null;
3994 }
3995 Object response = sendRequest(
3996 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3997 if (response instanceof String[]) {
3998 return (String[]) response;
3999 }
4000 // Response is an Exception of some kind,
4001 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004002 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004003 } finally {
4004 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004005 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004006 }
4007
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004008 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004009 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004010 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4011 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004012
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004013 final long identity = Binder.clearCallingIdentity();
4014 try {
4015 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4016 if (response.payload == null) {
4017 return "";
4018 }
Evan Charltonc66da362014-05-16 14:06:40 -07004019
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004020 // Append the returned status code to the end of the response payload.
4021 String s = Integer.toHexString(
4022 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4023 s = IccUtils.bytesToHexString(response.payload) + s;
4024 return s;
4025 } finally {
4026 Binder.restoreCallingIdentity(identity);
4027 }
Evan Charltonc66da362014-05-16 14:06:40 -07004028 }
4029
Jake Hambye994d462014-02-03 13:10:13 -08004030 /**
4031 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4032 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4033 *
4034 * @param itemID the ID of the item to read
4035 * @return the NV item as a String, or null on error.
4036 */
4037 @Override
4038 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004039 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004040 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4041 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004042
4043 final long identity = Binder.clearCallingIdentity();
4044 try {
4045 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004046 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004047 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4048 return value;
4049 } finally {
4050 Binder.restoreCallingIdentity(identity);
4051 }
Jake Hambye994d462014-02-03 13:10:13 -08004052 }
4053
4054 /**
4055 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4056 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4057 *
4058 * @param itemID the ID of the item to read
4059 * @param itemValue the value to write, as a String
4060 * @return true on success; false on any failure
4061 */
4062 @Override
4063 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004064 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004065 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4066 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004067
4068 final long identity = Binder.clearCallingIdentity();
4069 try {
4070 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4071 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004072 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004073 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4074 return success;
4075 } finally {
4076 Binder.restoreCallingIdentity(identity);
4077 }
Jake Hambye994d462014-02-03 13:10:13 -08004078 }
4079
4080 /**
4081 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4082 * Used for device configuration by some CDMA operators.
4083 *
4084 * @param preferredRoamingList byte array containing the new PRL
4085 * @return true on success; false on any failure
4086 */
4087 @Override
4088 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004089 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4090 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004091
4092 final long identity = Binder.clearCallingIdentity();
4093 try {
4094 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4095 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4096 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4097 return success;
4098 } finally {
4099 Binder.restoreCallingIdentity(identity);
4100 }
Jake Hambye994d462014-02-03 13:10:13 -08004101 }
4102
4103 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004104 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004105 * Used for device configuration by some CDMA operators.
4106 *
chen xu6dac5ab2018-10-26 17:39:23 -07004107 * @param slotIndex - device slot.
4108 *
Jake Hambye994d462014-02-03 13:10:13 -08004109 * @return true on success; false on any failure
4110 */
4111 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004112 public boolean resetModemConfig(int slotIndex) {
4113 Phone phone = PhoneFactory.getPhone(slotIndex);
4114 if (phone != null) {
4115 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4116 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004117
chen xu6dac5ab2018-10-26 17:39:23 -07004118 final long identity = Binder.clearCallingIdentity();
4119 try {
4120 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4121 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4122 return success;
4123 } finally {
4124 Binder.restoreCallingIdentity(identity);
4125 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004126 }
chen xu6dac5ab2018-10-26 17:39:23 -07004127 return false;
4128 }
4129
4130 /**
4131 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4132 *
4133 * @param slotIndex - device slot.
4134 *
4135 * @return true on success; false on any failure
4136 */
4137 @Override
4138 public boolean rebootModem(int slotIndex) {
4139 Phone phone = PhoneFactory.getPhone(slotIndex);
4140 if (phone != null) {
4141 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4142 mApp, phone.getSubId(), "rebootModem");
4143
4144 final long identity = Binder.clearCallingIdentity();
4145 try {
4146 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4147 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4148 return success;
4149 } finally {
4150 Binder.restoreCallingIdentity(identity);
4151 }
4152 }
4153 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004154 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004155
Svet Ganovb320e182015-04-16 12:30:10 -07004156 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004157 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004158 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004159 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004160 return new String[0];
4161 }
4162
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004163 final long identity = Binder.clearCallingIdentity();
4164 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004165 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004166 } finally {
4167 Binder.restoreCallingIdentity(identity);
4168 }
Wink Saville36469e72014-06-11 15:17:00 -07004169 }
4170
Brad Ebinger51f743a2017-01-23 13:50:20 -08004171 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004172 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4173 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004174 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004175 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004176 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004177
4178 final long identity = Binder.clearCallingIdentity();
4179 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004180 ImsResolver resolver = PhoneFactory.getImsResolver();
4181 if (resolver == null) {
4182 // may happen if the device does not support IMS.
4183 return;
4184 }
4185 resolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004186 } finally {
4187 Binder.restoreCallingIdentity(identity);
4188 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004189 }
4190
4191 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004192 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4193 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004194 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004195 public void disableIms(int slotId) {
4196 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004197
4198 final long identity = Binder.clearCallingIdentity();
4199 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004200 ImsResolver resolver = PhoneFactory.getImsResolver();
4201 if (resolver == null) {
4202 // may happen if the device does not support IMS.
4203 return;
4204 }
4205 resolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004206 } finally {
4207 Binder.restoreCallingIdentity(identity);
4208 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004209 }
4210
4211 /**
4212 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4213 * feature or {@link null} if the service is not available. If the feature is available, the
4214 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4215 */
4216 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004217 IImsServiceFeatureCallback callback) {
4218 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004219
4220 final long identity = Binder.clearCallingIdentity();
4221 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004222 ImsResolver resolver = PhoneFactory.getImsResolver();
4223 if (resolver == null) {
4224 // may happen if the device does not support IMS.
4225 return null;
4226 }
4227 return resolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004228 } finally {
4229 Binder.restoreCallingIdentity(identity);
4230 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004231 }
4232
4233 /**
4234 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4235 * feature during emergency calling or {@link null} if the service is not available. If the
4236 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4237 * listener for feature updates.
4238 */
4239 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4240 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004241
4242 final long identity = Binder.clearCallingIdentity();
4243 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004244 ImsResolver resolver = PhoneFactory.getImsResolver();
4245 if (resolver == null) {
4246 // may happen if the device does not support IMS.
4247 return null;
4248 }
4249 return resolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004250 } finally {
4251 Binder.restoreCallingIdentity(identity);
4252 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004253 }
4254
Brad Ebinger5f64b052017-12-14 14:26:15 -08004255 /**
4256 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004257 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004258 */
4259 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4260 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004261
4262 final long identity = Binder.clearCallingIdentity();
4263 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004264 ImsResolver resolver = PhoneFactory.getImsResolver();
4265 if (resolver == null) {
4266 // may happen if the device does not support IMS.
4267 return null;
4268 }
4269 return resolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004270 } finally {
4271 Binder.restoreCallingIdentity(identity);
4272 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004273 }
4274
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004275 /**
4276 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004277 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004278 */
4279 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4280 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004281
4282 final long identity = Binder.clearCallingIdentity();
4283 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004284 ImsResolver resolver = PhoneFactory.getImsResolver();
4285 if (resolver == null) {
4286 // may happen if the device does not support IMS.
4287 return null;
4288 }
4289 return resolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004290 } finally {
4291 Binder.restoreCallingIdentity(identity);
4292 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004293 }
4294
Brad Ebinger884c07b2018-02-15 16:17:40 -08004295 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004296 * Sets the ImsService Package Name that Telephony will bind to.
4297 *
4298 * @param slotId the slot ID that the ImsService should bind for.
4299 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4300 * ImsService is the device default ImsService.
4301 * @param packageName The package name of the application that contains the ImsService to bind
4302 * to.
4303 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4304 * @hide
4305 */
4306 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004307 int[] subIds = SubscriptionManager.getSubId(slotId);
4308 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4309 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4310 "setImsService");
4311
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004312 final long identity = Binder.clearCallingIdentity();
4313 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004314 ImsResolver resolver = PhoneFactory.getImsResolver();
4315 if (resolver == null) {
4316 // may happen if the device does not support IMS.
4317 return false;
4318 }
4319 return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService,
4320 packageName);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004321 } finally {
4322 Binder.restoreCallingIdentity(identity);
4323 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004324 }
4325
4326 /**
4327 * Return the ImsService configuration.
4328 *
4329 * @param slotId The slot that the ImsService is associated with.
4330 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4331 * the device default.
4332 * @return the package name of the ImsService configuration.
4333 */
4334 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004335 int[] subIds = SubscriptionManager.getSubId(slotId);
4336 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4337 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4338 "getImsService");
4339
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004340 final long identity = Binder.clearCallingIdentity();
4341 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004342 ImsResolver resolver = PhoneFactory.getImsResolver();
4343 if (resolver == null) {
4344 // may happen if the device does not support IMS.
4345 return "";
4346 }
4347 return resolver.getImsServiceConfiguration(slotId, isCarrierImsService);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004348 } finally {
4349 Binder.restoreCallingIdentity(identity);
4350 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004351 }
4352
Wink Saville36469e72014-06-11 15:17:00 -07004353 public void setImsRegistrationState(boolean registered) {
4354 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004355
4356 final long identity = Binder.clearCallingIdentity();
4357 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004358 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004359 } finally {
4360 Binder.restoreCallingIdentity(identity);
4361 }
Wink Saville36469e72014-06-11 15:17:00 -07004362 }
4363
4364 /**
Stuart Scott54788802015-03-30 13:18:01 -07004365 * Set the network selection mode to automatic.
4366 *
4367 */
4368 @Override
4369 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004370 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4371 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004372
Pengquan Menge92a50d2018-09-21 15:54:48 -07004373 if (!isActiveSubscription(subId)) {
4374 return;
4375 }
4376
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004377 final long identity = Binder.clearCallingIdentity();
4378 try {
4379 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4380 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4381 } finally {
4382 Binder.restoreCallingIdentity(identity);
4383 }
Stuart Scott54788802015-03-30 13:18:01 -07004384 }
4385
Pengquan Mengea84e042018-09-20 14:57:26 -07004386 /**
4387 * Ask the radio to connect to the input network and change selection mode to manual.
4388 *
4389 * @param subId the id of the subscription.
4390 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4391 * the operator to attach to.
4392 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4393 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4394 * normal network selection next time.
4395 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004396 */
4397 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004398 public boolean setNetworkSelectionModeManual(
4399 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004400 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4401 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004402
4403 if (!isActiveSubscription(subId)) {
4404 return false;
4405 }
4406
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004407 final long identity = Binder.clearCallingIdentity();
4408 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004409 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004410 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004411 if (DBG) {
4412 log("setNetworkSelectionModeManual: subId: " + subId
4413 + " operator: " + operatorInfo);
4414 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004415 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4416 } finally {
4417 Binder.restoreCallingIdentity(identity);
4418 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004419 }
4420
4421 /**
4422 * Scans for available networks.
4423 */
4424 @Override
Hall Liuf19c44f2018-11-27 14:38:17 -08004425 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004426 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4427 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004428 LocationAccessPolicy.LocationPermissionResult locationResult =
4429 LocationAccessPolicy.checkLocationPermission(mApp,
4430 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4431 .setCallingPackage(callingPackage)
4432 .setCallingPid(Binder.getCallingPid())
4433 .setCallingUid(Binder.getCallingUid())
4434 .setMethod("getCellNetworkScanResults")
4435 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4436 .build());
4437 switch (locationResult) {
4438 case DENIED_HARD:
4439 throw new SecurityException("Not allowed to access scan results -- location");
4440 case DENIED_SOFT:
4441 return null;
4442 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004443
Pengquan Menga1bb6272018-09-06 09:59:22 -07004444 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004445 try {
4446 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004447 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004448 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004449 } finally {
4450 Binder.restoreCallingIdentity(identity);
4451 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004452 }
4453
4454 /**
yinxub1bed742017-04-17 11:45:04 -07004455 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004456 *
yinxub1bed742017-04-17 11:45:04 -07004457 * @param subId id of the subscription
4458 * @param request contains the radio access networks with bands/channels to scan
4459 * @param messenger callback messenger for scan results or errors
4460 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004461 * @return the id of the requested scan which can be used to stop the scan.
4462 */
4463 @Override
4464 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Hall Liuf19c44f2018-11-27 14:38:17 -08004465 IBinder binder, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004466 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4467 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004468 LocationAccessPolicy.LocationPermissionResult locationResult =
4469 LocationAccessPolicy.checkLocationPermission(mApp,
4470 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4471 .setCallingPackage(callingPackage)
4472 .setCallingPid(Binder.getCallingPid())
4473 .setCallingUid(Binder.getCallingUid())
4474 .setMethod("requestNetworkScan")
4475 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4476 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004477 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
4478 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request);
4479 if (e != null) {
4480 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4481 throw e;
4482 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07004483 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004484 return TelephonyScanManager.INVALID_SCAN_ID;
4485 }
4486 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004487 }
Hall Liu912dfd32019-04-25 14:02:26 -07004488 int callingUid = Binder.getCallingUid();
4489 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07004490 final long identity = Binder.clearCallingIdentity();
4491 try {
4492 return mNetworkScanRequestTracker.startNetworkScan(
4493 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07004494 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07004495 } finally {
4496 Binder.restoreCallingIdentity(identity);
4497 }
yinxu504e1392017-04-12 16:03:22 -07004498 }
4499
Hall Liub2ac8ef2019-02-28 15:56:23 -08004500 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
4501 NetworkScanRequest request) {
4502 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4503 != PERMISSION_GRANTED) {
4504 return new SecurityException("permission.NETWORK_SCAN is needed for network scans"
4505 + " without location access.");
4506 }
4507
4508 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4509 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004510 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4511 return new SecurityException("Specific channels must not be"
4512 + " scanned without location access.");
4513 }
4514 }
4515 }
4516
Hall Liub2ac8ef2019-02-28 15:56:23 -08004517 return null;
4518 }
4519
yinxu504e1392017-04-12 16:03:22 -07004520 /**
4521 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004522 *
4523 * @param subId id of the subscription
4524 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004525 */
4526 @Override
4527 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004528 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4529 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004530
Hall Liu912dfd32019-04-25 14:02:26 -07004531 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004532 final long identity = Binder.clearCallingIdentity();
4533 try {
Hall Liu912dfd32019-04-25 14:02:26 -07004534 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004535 } finally {
4536 Binder.restoreCallingIdentity(identity);
4537 }
yinxu504e1392017-04-12 16:03:22 -07004538 }
4539
4540 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004541 * Get the calculated preferred network type.
4542 * Used for debugging incorrect network type.
4543 *
4544 * @return the preferred network type, defined in RILConstants.java.
4545 */
4546 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004547 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004548 final Phone defaultPhone = getDefaultPhone();
4549 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4550 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004551 return RILConstants.PREFERRED_NETWORK_MODE;
4552 }
4553
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004554 final long identity = Binder.clearCallingIdentity();
4555 try {
4556 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004557 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004558 } finally {
4559 Binder.restoreCallingIdentity(identity);
4560 }
Junda Liu84d15a22014-07-02 11:21:04 -07004561 }
4562
4563 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004564 * Get the preferred network type.
4565 * Used for device configuration by some CDMA operators.
4566 *
4567 * @return the preferred network type, defined in RILConstants.java.
4568 */
4569 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004570 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08004571 TelephonyPermissions
4572 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4573 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004574
4575 final long identity = Binder.clearCallingIdentity();
4576 try {
4577 if (DBG) log("getPreferredNetworkType");
4578 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4579 int networkType = (result != null ? result[0] : -1);
4580 if (DBG) log("getPreferredNetworkType: " + networkType);
4581 return networkType;
4582 } finally {
4583 Binder.restoreCallingIdentity(identity);
4584 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004585 }
4586
4587 /**
4588 * Set the preferred network type.
4589 * Used for device configuration by some CDMA operators.
4590 *
4591 * @param networkType the preferred network type, defined in RILConstants.java.
4592 * @return true on success; false on any failure.
4593 */
4594 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004595 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004596 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4597 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004598
4599 final long identity = Binder.clearCallingIdentity();
4600 try {
4601 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4602 Boolean success = (Boolean) sendRequest(
4603 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4604 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4605 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004606 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004607 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4608 }
4609 return success;
4610 } finally {
4611 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004612 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004613 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004614
4615 /**
Miaoa84611c2019-03-15 09:21:10 +08004616 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004617 *
Miaoa84611c2019-03-15 09:21:10 +08004618 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004619 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004620 * @hide
4621 */
4622 @Override
Miaoa84611c2019-03-15 09:21:10 +08004623 public boolean getTetherApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004624 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004625 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08004626 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004627 try {
Miaoa84611c2019-03-15 09:21:10 +08004628 if (phone != null) {
4629 return phone.hasMatchedTetherApnSetting();
4630 } else {
4631 return false;
4632 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004633 } finally {
4634 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004635 }
Junda Liu475951f2014-11-07 16:45:03 -08004636 }
4637
4638 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004639 * Set mobile data enabled
4640 * Used by the user through settings etc to turn on/off mobile data
4641 *
4642 * @param enable {@code true} turn turn data on, else {@code false}
4643 */
4644 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004645 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004646 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4647 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004648
4649 final long identity = Binder.clearCallingIdentity();
4650 try {
4651 int phoneId = mSubscriptionController.getPhoneId(subId);
4652 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4653 Phone phone = PhoneFactory.getPhone(phoneId);
4654 if (phone != null) {
4655 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08004656 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004657 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004658 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004659 }
4660 } finally {
4661 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004662 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004663 }
4664
4665 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004666 * Get the user enabled state of Mobile Data.
4667 *
4668 * TODO: remove and use isUserDataEnabled.
4669 * This can't be removed now because some vendor codes
4670 * calls through ITelephony directly while they should
4671 * use TelephonyManager.
4672 *
4673 * @return true on enabled
4674 */
4675 @Override
4676 public boolean getDataEnabled(int subId) {
4677 return isUserDataEnabled(subId);
4678 }
4679
4680 /**
4681 * Get whether mobile data is enabled per user setting.
4682 *
4683 * There are other factors deciding whether mobile data is actually enabled, but they are
4684 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004685 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004686 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004687 *
4688 * @return {@code true} if data is enabled else {@code false}
4689 */
4690 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004691 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004692 try {
4693 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4694 null);
4695 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004696 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4697 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004698 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004699
4700 final long identity = Binder.clearCallingIdentity();
4701 try {
4702 int phoneId = mSubscriptionController.getPhoneId(subId);
4703 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4704 Phone phone = PhoneFactory.getPhone(phoneId);
4705 if (phone != null) {
4706 boolean retVal = phone.isUserDataEnabled();
4707 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4708 return retVal;
4709 } else {
4710 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4711 return false;
4712 }
4713 } finally {
4714 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004715 }
4716 }
4717
4718 /**
4719 * Get whether mobile data is enabled.
4720 *
4721 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4722 * whether mobile data is actually enabled.
4723 *
4724 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4725 *
4726 * @return {@code true} if data is enabled else {@code false}
4727 */
4728 @Override
4729 public boolean isDataEnabled(int subId) {
4730 try {
4731 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4732 null);
4733 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004734 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4735 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004736 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004737
4738 final long identity = Binder.clearCallingIdentity();
4739 try {
4740 int phoneId = mSubscriptionController.getPhoneId(subId);
4741 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4742 Phone phone = PhoneFactory.getPhone(phoneId);
4743 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08004744 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004745 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4746 return retVal;
4747 } else {
4748 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4749 return false;
4750 }
4751 } finally {
4752 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004753 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004754 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004755
4756 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004757 public int getCarrierPrivilegeStatus(int subId) {
4758 final Phone phone = getPhone(subId);
4759 if (phone == null) {
4760 loge("getCarrierPrivilegeStatus: Invalid subId");
4761 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4762 }
4763 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004764 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004765 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004766 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4767 }
4768 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004769 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004770 }
Junda Liu29340342014-07-10 15:23:27 -07004771
4772 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004773 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4774 final Phone phone = getPhone(subId);
4775 if (phone == null) {
4776 loge("getCarrierPrivilegeStatus: Invalid subId");
4777 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4778 }
4779 UiccProfile profile =
4780 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4781 if (profile == null) {
4782 loge("getCarrierPrivilegeStatus: No UICC");
4783 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4784 }
4785 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4786 }
4787
4788 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07004789 public int checkCarrierPrivilegesForPackage(String pkgName) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004790 final Phone defaultPhone = getDefaultPhone();
Junda Liu317d70b2016-03-08 09:33:53 -08004791 if (TextUtils.isEmpty(pkgName))
4792 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004793 UiccCard card = UiccController.getInstance().getUiccCard(defaultPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004794 if (card == null) {
4795 loge("checkCarrierPrivilegesForPackage: No UICC");
4796 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4797 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004798 return card.getCarrierPrivilegeStatus(defaultPhone.getContext().getPackageManager(),
4799 pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004800 }
4801
4802 @Override
4803 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004804 if (TextUtils.isEmpty(pkgName))
4805 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004806 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4807 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4808 UiccCard card = UiccController.getInstance().getUiccCard(i);
4809 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004810 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004811 continue;
4812 }
4813
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004814 result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004815 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4816 break;
4817 }
4818 }
4819
4820 return result;
Junda Liu29340342014-07-10 15:23:27 -07004821 }
Derek Tan89e89d42014-07-08 17:00:10 -07004822
4823 @Override
Junda Liue64de782015-04-16 17:19:16 -07004824 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4825 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4826 loge("phoneId " + phoneId + " is not valid.");
4827 return null;
4828 }
4829 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004830 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004831 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004832 return null ;
4833 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004834 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004835 }
4836
Amith Yamasani6e118872016-02-19 12:53:51 -08004837 @Override
4838 public List<String> getPackagesWithCarrierPrivileges() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004839 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08004840 List<String> privilegedPackages = new ArrayList<>();
4841 List<PackageInfo> packages = null;
4842 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4843 UiccCard card = UiccController.getInstance().getUiccCard(i);
4844 if (card == null) {
4845 // No UICC in that slot.
4846 continue;
4847 }
4848 if (card.hasCarrierPrivilegeRules()) {
4849 if (packages == null) {
4850 // Only check packages in user 0 for now
4851 packages = pm.getInstalledPackagesAsUser(
4852 PackageManager.MATCH_DISABLED_COMPONENTS
4853 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4854 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
4855 }
4856 for (int p = packages.size() - 1; p >= 0; p--) {
4857 PackageInfo pkgInfo = packages.get(p);
4858 if (pkgInfo != null && pkgInfo.packageName != null
4859 && card.getCarrierPrivilegeStatus(pkgInfo)
4860 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4861 privilegedPackages.add(pkgInfo.packageName);
4862 }
4863 }
4864 }
4865 }
4866 return privilegedPackages;
4867 }
4868
Wink Savilleb564aae2014-10-23 10:18:09 -07004869 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004870 final Phone phone = getPhone(subId);
4871 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004872 if (card == null) {
4873 loge("getIccId: No UICC");
4874 return null;
4875 }
4876 String iccId = card.getIccId();
4877 if (TextUtils.isEmpty(iccId)) {
4878 loge("getIccId: ICC ID is null or empty.");
4879 return null;
4880 }
4881 return iccId;
4882 }
4883
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004884 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004885 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4886 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004887 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4888 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004889
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004890 final long identity = Binder.clearCallingIdentity();
4891 try {
4892 final String iccId = getIccId(subId);
4893 final Phone phone = getPhone(subId);
4894 if (phone == null) {
4895 return false;
4896 }
4897 final String subscriberId = phone.getSubscriberId();
4898
4899 if (DBG_MERGE) {
4900 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4901 + subscriberId + " to " + number);
4902 }
4903
4904 if (TextUtils.isEmpty(iccId)) {
4905 return false;
4906 }
4907
4908 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4909
4910 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4911 if (alphaTag == null) {
4912 editor.remove(alphaTagPrefKey);
4913 } else {
4914 editor.putString(alphaTagPrefKey, alphaTag);
4915 }
4916
4917 // Record both the line number and IMSI for this ICCID, since we need to
4918 // track all merged IMSIs based on line number
4919 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4920 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4921 if (number == null) {
4922 editor.remove(numberPrefKey);
4923 editor.remove(subscriberPrefKey);
4924 } else {
4925 editor.putString(numberPrefKey, number);
4926 editor.putString(subscriberPrefKey, subscriberId);
4927 }
4928
4929 editor.commit();
4930 return true;
4931 } finally {
4932 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004933 }
Derek Tan7226c842014-07-02 17:42:23 -07004934 }
4935
4936 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004937 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004938 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004939 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004940 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004941 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004942 return null;
4943 }
Derek Tan97ebb422014-09-05 16:55:38 -07004944
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004945 final long identity = Binder.clearCallingIdentity();
4946 try {
4947 String iccId = getIccId(subId);
4948 if (iccId != null) {
4949 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4950 if (DBG_MERGE) {
4951 log("getLine1NumberForDisplay returning "
4952 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4953 }
4954 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004955 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004956 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4957 return null;
4958 } finally {
4959 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004960 }
Derek Tan7226c842014-07-02 17:42:23 -07004961 }
4962
4963 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004964 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004965 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004966 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004967 return null;
4968 }
Derek Tan97ebb422014-09-05 16:55:38 -07004969
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004970 final long identity = Binder.clearCallingIdentity();
4971 try {
4972 String iccId = getIccId(subId);
4973 if (iccId != null) {
4974 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4975 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4976 }
4977 return null;
4978 } finally {
4979 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004980 }
Derek Tan7226c842014-07-02 17:42:23 -07004981 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004982
4983 @Override
Jordan Liub49b04b2019-05-06 14:45:15 -07004984 public String[] getMergedSubscriberIds(int subId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004985 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4986 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004987 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004988 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4989 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004990 return null;
4991 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004992
Jordan Liub49b04b2019-05-06 14:45:15 -07004993 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4994 // the process, where TelephonyManager was instantiated.
4995 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004996 final long identity = Binder.clearCallingIdentity();
4997 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004998 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004999 final TelephonyManager tele = TelephonyManager.from(context);
5000 final SubscriptionManager sub = SubscriptionManager.from(context);
5001
5002 // Figure out what subscribers are currently active
5003 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005004
Jordan Liub49b04b2019-05-06 14:45:15 -07005005 // Only consider subs which match the current subId
5006 // This logic can be simplified. See b/131189269 for progress.
5007 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005008 activeSubscriberIds.add(tele.getSubscriberId(subId));
5009 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005010
5011 // First pass, find a number override for an active subscriber
5012 String mergeNumber = null;
5013 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5014 for (String key : prefs.keySet()) {
5015 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5016 final String subscriberId = (String) prefs.get(key);
5017 if (activeSubscriberIds.contains(subscriberId)) {
5018 final String iccId = key.substring(
5019 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5020 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5021 mergeNumber = (String) prefs.get(numberKey);
5022 if (DBG_MERGE) {
5023 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5024 + " for active subscriber " + subscriberId);
5025 }
5026 if (!TextUtils.isEmpty(mergeNumber)) {
5027 break;
5028 }
5029 }
5030 }
5031 }
5032
5033 // Shortcut when no active merged subscribers
5034 if (TextUtils.isEmpty(mergeNumber)) {
5035 return null;
5036 }
5037
5038 // Second pass, find all subscribers under that line override
5039 final ArraySet<String> result = new ArraySet<>();
5040 for (String key : prefs.keySet()) {
5041 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5042 final String number = (String) prefs.get(key);
5043 if (mergeNumber.equals(number)) {
5044 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5045 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5046 final String subscriberId = (String) prefs.get(subscriberKey);
5047 if (!TextUtils.isEmpty(subscriberId)) {
5048 result.add(subscriberId);
5049 }
5050 }
5051 }
5052 }
5053
5054 final String[] resultArray = result.toArray(new String[result.size()]);
5055 Arrays.sort(resultArray);
5056 if (DBG_MERGE) {
5057 Slog.d(LOG_TAG,
5058 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5059 }
5060 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005061 } finally {
5062 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005063 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005064 }
5065
5066 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005067 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005068 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5069 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005070
5071 final long identity = Binder.clearCallingIdentity();
5072 try {
5073 final Phone phone = getPhone(subId);
5074 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5075 } finally {
5076 Binder.restoreCallingIdentity(identity);
5077 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005078 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005079
5080 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005081 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005082 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5083 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005084 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005085
5086 final long identity = Binder.clearCallingIdentity();
5087 try {
5088 final Phone phone = getPhone(subId);
5089 if (phone == null) {
5090 return false;
5091 }
5092 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5093 cdmaNonRoamingList);
5094 } finally {
5095 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005096 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005097 }
5098
5099 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005100 @Deprecated
5101 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5102 enforceModifyPermission();
5103
5104 int returnValue = 0;
5105 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005106 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005107 if(result.exception == null) {
5108 if (result.result != null) {
5109 byte[] responseData = (byte[])(result.result);
5110 if(responseData.length > oemResp.length) {
5111 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5112 responseData.length + "bytes. Buffer Size is " +
5113 oemResp.length + "bytes.");
5114 }
5115 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5116 returnValue = responseData.length;
5117 }
5118 } else {
5119 CommandException ex = (CommandException) result.exception;
5120 returnValue = ex.getCommandError().ordinal();
5121 if(returnValue > 0) returnValue *= -1;
5122 }
5123 } catch (RuntimeException e) {
5124 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5125 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5126 if(returnValue > 0) returnValue *= -1;
5127 }
5128
5129 return returnValue;
5130 }
5131
5132 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005133 public void setRadioCapability(RadioAccessFamily[] rafs) {
5134 try {
5135 ProxyController.getInstance().setRadioCapability(rafs);
5136 } catch (RuntimeException e) {
5137 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5138 }
5139 }
5140
5141 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005142 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005143 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005144 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005145 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005146 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005147 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005148 final long identity = Binder.clearCallingIdentity();
5149 try {
chen xub97461a2018-10-26 14:17:57 -07005150 TelephonyPermissions
5151 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5152 mApp, phone.getSubId(), "getRadioAccessFamily");
5153 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005154 } finally {
5155 Binder.restoreCallingIdentity(identity);
5156 }
chen xub97461a2018-10-26 14:17:57 -07005157 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005158 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005159
5160 @Override
5161 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005162 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005163 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005164
5165 final long identity = Binder.clearCallingIdentity();
5166 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005167 ImsManager.getInstance(defaultPhone.getContext(),
5168 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005169 } finally {
5170 Binder.restoreCallingIdentity(identity);
5171 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005172 }
5173
5174 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005175 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005176 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00005177 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005178 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005179 return false;
5180 }
Svet Ganovb320e182015-04-16 12:30:10 -07005181
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005182 final long identity = Binder.clearCallingIdentity();
5183 try {
5184 // Check the user preference and the system-level IMS setting. Even if the user has
5185 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5186 // In the long run, we may instead need to check if there exists a connection service
5187 // which can support video calling.
5188 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005189 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005190 return imsManager.isVtEnabledByPlatform()
5191 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5192 && imsManager.isVtEnabledByUser();
5193 } finally {
5194 Binder.restoreCallingIdentity(identity);
5195 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005196 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005197
Andrew Leea1239f22015-03-02 17:44:07 -08005198 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005199 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
5200 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5201 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5202 return false;
5203 }
5204
5205 final long identity = Binder.clearCallingIdentity();
5206 try {
5207 CarrierConfigManager configManager =
5208 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005209 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005210 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5211 } finally {
5212 Binder.restoreCallingIdentity(identity);
5213 }
Andrew Leea1239f22015-03-02 17:44:07 -08005214 }
5215
5216 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005217 public boolean isWorldPhone(int subId, String callingPackage) {
5218 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5219 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5220 return false;
5221 }
5222
5223 final long identity = Binder.clearCallingIdentity();
5224 try {
5225 CarrierConfigManager configManager =
5226 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005227 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005228 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5229 } finally {
5230 Binder.restoreCallingIdentity(identity);
5231 }
Andrew Leea1239f22015-03-02 17:44:07 -08005232 }
5233
Andrew Lee9431b832015-03-09 18:46:45 -07005234 @Override
5235 public boolean isTtyModeSupported() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005236 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005237 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005238 }
5239
5240 @Override
5241 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005242 final long identity = Binder.clearCallingIdentity();
5243 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005244 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005245 } finally {
5246 Binder.restoreCallingIdentity(identity);
5247 }
Andrew Lee9431b832015-03-09 18:46:45 -07005248 }
5249
Hall Liuf6668912018-10-31 17:05:23 -07005250 /**
5251 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5252 * support for the feature and device firmware support.
5253 *
5254 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5255 */
5256 @Override
5257 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005258 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005259 final Phone phone = getPhone(subscriptionId);
5260 if (phone == null) {
5261 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5262 return false;
5263 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005264 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005265 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005266 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5267 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005268 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005269 return isCarrierSupported && isDeviceSupported;
5270 } finally {
5271 Binder.restoreCallingIdentity(identity);
5272 }
Hall Liu98187582018-01-22 19:15:32 -08005273 }
5274
Hall Liuf6668912018-10-31 17:05:23 -07005275 /**
5276 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
5277 * both also support RTT.
5278 */
5279 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005280 final long identity = Binder.clearCallingIdentity();
5281 try {
Hall Liuf6668912018-10-31 17:05:23 -07005282 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005283 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005284 } finally {
5285 Binder.restoreCallingIdentity(identity);
5286 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005287 }
5288
Sanket Padawe7310cc72015-01-14 09:53:20 -08005289 /**
5290 * Returns the unique device ID of phone, for example, the IMEI for
5291 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5292 *
5293 * <p>Requires Permission:
5294 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5295 */
5296 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005297 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005298 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005299 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005300 return null;
5301 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005302 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005303 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
5304 callingPackage, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005305 return null;
5306 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005307
5308 final long identity = Binder.clearCallingIdentity();
5309 try {
5310 return phone.getDeviceId();
5311 } finally {
5312 Binder.restoreCallingIdentity(identity);
5313 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005314 }
5315
Ping Sunc67b7c22016-03-02 19:16:45 +08005316 /**
5317 * {@hide}
5318 * Returns the IMS Registration Status on a particular subid
5319 *
5320 * @param subId
5321 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005322 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005323 Phone phone = getPhone(subId);
5324 if (phone != null) {
5325 return phone.isImsRegistered();
5326 } else {
5327 return false;
5328 }
5329 }
5330
Santos Cordon7a1885b2015-02-03 11:15:19 -08005331 @Override
5332 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005333 final long identity = Binder.clearCallingIdentity();
5334 try {
5335 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5336 } finally {
5337 Binder.restoreCallingIdentity(identity);
5338 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005339 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005340
Tyler Gunnf70ed162019-04-03 15:28:53 -07005341 @Override
5342 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5343 final long identity = Binder.clearCallingIdentity();
5344 try {
5345 Phone phone = getPhone(subscriptionId);
5346 if (phone == null) {
5347 return null;
5348 }
5349 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5350 } finally {
5351 Binder.restoreCallingIdentity(identity);
5352 }
5353 }
5354
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005355 /**
5356 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005357 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005358 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005359 final long identity = Binder.clearCallingIdentity();
5360 try {
5361 Phone phone = getPhone(subId);
5362 if (phone != null) {
5363 return phone.isWifiCallingEnabled();
5364 } else {
5365 return false;
5366 }
5367 } finally {
5368 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005369 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005370 }
5371
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005372 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005373 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005374 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005375 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005376 final long identity = Binder.clearCallingIdentity();
5377 try {
5378 Phone phone = getPhone(subId);
5379 if (phone != null) {
5380 return phone.isVideoEnabled();
5381 } else {
5382 return false;
5383 }
5384 } finally {
5385 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005386 }
5387 }
5388
5389 /**
5390 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5391 * defined in {@link ImsRegistrationImplBase}.
5392 */
5393 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005394 final long identity = Binder.clearCallingIdentity();
5395 try {
5396 Phone phone = getPhone(subId);
5397 if (phone != null) {
5398 return phone.getImsRegistrationTech();
5399 } else {
5400 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5401 }
5402 } finally {
5403 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005404 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005405 }
5406
Stuart Scott8eef64f2015-04-08 15:13:54 -07005407 @Override
5408 public void factoryReset(int subId) {
5409 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005410 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5411 return;
5412 }
5413
Svet Ganovcc087f82015-05-12 20:35:54 -07005414 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005415
Svet Ganovcc087f82015-05-12 20:35:54 -07005416 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005417 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5418 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005419 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005420 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005421 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005422 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5423 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005424 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005425 // There has been issues when Sms raw table somehow stores orphan
5426 // fragments. They lead to garbled message when new fragments come
5427 // in and combined with those stale ones. In case this happens again,
5428 // user can reset all network settings which will clean up this table.
5429 cleanUpSmsRawTable(getDefaultPhone().getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07005430 } finally {
5431 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005432 }
5433 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005434
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005435 private void cleanUpSmsRawTable(Context context) {
5436 ContentResolver resolver = context.getContentResolver();
5437 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5438 resolver.delete(uri, null, null);
5439 }
5440
Narayan Kamath1c496c22015-04-16 14:40:19 +01005441 @Override
chen xu5d3637b2019-01-21 23:31:38 -08005442 public String getSimLocaleForSubscriber(int subId) {
5443 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5444 final Phone phone = getPhone(subId);
5445 if (phone == null) {
5446 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08005447 return null;
chen xu5d3637b2019-01-21 23:31:38 -08005448 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005449 final long identity = Binder.clearCallingIdentity();
5450 try {
chen xu5d3637b2019-01-21 23:31:38 -08005451 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5452 phone.getContext().getOpPackageName());
chen xu6291c472019-02-04 12:55:53 -08005453 if (info == null) {
5454 log("getSimLocaleForSubscriber, inactive subId: " + subId);
5455 return null;
5456 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005457 // Try and fetch the locale from the carrier properties or from the SIM language
5458 // preferences (EF-PL and EF-LI)...
5459 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005460 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08005461 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5462 if (localeFromDefaultSim != null) {
5463 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5464 if (DBG) log("Using locale from subId: " + subId + " locale: "
5465 + localeFromDefaultSim);
5466 return localeFromDefaultSim.toLanguageTag();
5467 } else {
5468 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005469 }
5470 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005471
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005472 // The SIM language preferences only store a language (e.g. fr = French), not an
5473 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5474 // the SIM and carrier preferences does not include a country we add the country
5475 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005476 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005477 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08005478 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005479 return mccLocale.toLanguageTag();
5480 }
5481
5482 if (DBG) log("No locale found - returning null");
5483 return null;
5484 } finally {
5485 Binder.restoreCallingIdentity(identity);
5486 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005487 }
5488
5489 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005490 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005491 }
5492
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005493 /**
5494 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5495 */
5496 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005497 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005498 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005499
Chenjie Yu1ba97252018-01-11 18:16:20 -08005500 private final ModemActivityInfo mLastModemActivityInfo =
5501 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
5502
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005503 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005504 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5505 * representing the state of the modem.
5506 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005507 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5508 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005509 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005510 */
5511 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005512 public void requestModemActivityInfo(ResultReceiver result) {
5513 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005514 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005515
5516 final long identity = Binder.clearCallingIdentity();
5517 try {
5518 ModemActivityInfo ret = null;
5519 synchronized (mLastModemActivityInfo) {
5520 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5521 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07005522 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07005523 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005524 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
5525 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005526 mergedTxTimeMs[i] = info.getTxTimeMillis()[i]
5527 + mLastModemActivityInfo.getTxTimeMillis()[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005528 }
5529 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005530 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
5531 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005532 mLastModemActivityInfo.setIdleTimeMillis(
5533 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
5534 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
5535 mLastModemActivityInfo.setRxTimeMillis(
5536 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
5537 mLastModemActivityInfo.setEnergyUsed(
5538 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005539 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005540 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
5541 mLastModemActivityInfo.getSleepTimeMillis(),
5542 mLastModemActivityInfo.getIdleTimeMillis(),
5543 mLastModemActivityInfo.getTxTimeMillis(),
5544 mLastModemActivityInfo.getRxTimeMillis(),
5545 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005546 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005547 Bundle bundle = new Bundle();
5548 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
5549 result.send(0, bundle);
5550 } finally {
5551 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005552 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005553 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005554
Siddharth Rayb8114062018-06-17 15:02:38 -07005555 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
5556 // less than total activity duration.
5557 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
5558 if (info == null) {
5559 return false;
5560 }
5561 int activityDurationMs =
5562 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
5563 int totalTxTimeMs = 0;
5564 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
5565 totalTxTimeMs += info.getTxTimeMillis()[i];
5566 }
5567 return (info.isValid()
5568 && (info.getSleepTimeMillis() <= activityDurationMs)
5569 && (info.getIdleTimeMillis() <= activityDurationMs)
5570 && (info.getRxTimeMillis() <= activityDurationMs)
5571 && (totalTxTimeMs <= activityDurationMs));
5572 }
5573
Jack Yu85bd38a2015-11-09 11:34:32 -08005574 /**
5575 * {@hide}
5576 * Returns the service state information on specified subscription.
5577 */
5578 @Override
5579 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005580 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005581 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08005582 return null;
5583 }
5584
Hall Liuf19c44f2018-11-27 14:38:17 -08005585 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
5586 LocationAccessPolicy.checkLocationPermission(mApp,
5587 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5588 .setCallingPackage(callingPackage)
5589 .setCallingPid(Binder.getCallingPid())
5590 .setCallingUid(Binder.getCallingUid())
5591 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07005592 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005593 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5594 .build());
5595
5596 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
5597 LocationAccessPolicy.checkLocationPermission(mApp,
5598 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5599 .setCallingPackage(callingPackage)
5600 .setCallingPid(Binder.getCallingPid())
5601 .setCallingUid(Binder.getCallingUid())
5602 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07005603 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005604 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5605 .build());
5606 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
5607 boolean hasFinePermission =
5608 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5609 boolean hasCoarsePermission =
5610 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5611
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005612 final long identity = Binder.clearCallingIdentity();
5613 try {
5614 final Phone phone = getPhone(subId);
5615 if (phone == null) {
5616 return null;
5617 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005618
Hall Liuf19c44f2018-11-27 14:38:17 -08005619 ServiceState ss = phone.getServiceState();
5620
5621 // Scrub out the location info in ServiceState depending on what level of access
5622 // the caller has.
5623 if (hasFinePermission) return ss;
5624 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
5625 return ss.sanitizeLocationInfo(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005626 } finally {
5627 Binder.restoreCallingIdentity(identity);
5628 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005629 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005630
5631 /**
5632 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
5633 *
5634 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5635 * voicemail ringtone.
5636 * @return The URI for the ringtone to play when receiving a voicemail from a specific
5637 * PhoneAccount.
5638 */
5639 @Override
5640 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005641 final long identity = Binder.clearCallingIdentity();
5642 try {
5643 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5644 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005645 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005646 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005647
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005648 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
5649 } finally {
5650 Binder.restoreCallingIdentity(identity);
5651 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005652 }
5653
5654 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005655 * Sets the per-account voicemail ringtone.
5656 *
5657 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5658 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5659 *
5660 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5661 * voicemail ringtone.
5662 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5663 * PhoneAccount.
5664 */
5665 @Override
5666 public void setVoicemailRingtoneUri(String callingPackage,
5667 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005668 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005669 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5670 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005671 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005672 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5673 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5674 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005675 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005676
5677 final long identity = Binder.clearCallingIdentity();
5678 try {
5679 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5680 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005681 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005682 }
5683 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5684 } finally {
5685 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005686 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005687 }
5688
5689 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005690 * Returns whether vibration is set for voicemail notification in Phone settings.
5691 *
5692 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5693 * voicemail vibration setting.
5694 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5695 */
5696 @Override
5697 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005698 final long identity = Binder.clearCallingIdentity();
5699 try {
5700 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5701 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005702 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005703 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005704
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005705 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5706 } finally {
5707 Binder.restoreCallingIdentity(identity);
5708 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005709 }
5710
Youhan Wange64578a2016-05-02 15:32:42 -07005711 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005712 * Sets the per-account voicemail vibration.
5713 *
5714 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5715 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5716 *
5717 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5718 * voicemail vibration setting.
5719 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5720 * specific PhoneAccount.
5721 */
5722 @Override
5723 public void setVoicemailVibrationEnabled(String callingPackage,
5724 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005725 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005726 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5727 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005728 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005729 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5730 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5731 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005732 }
5733
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005734 final long identity = Binder.clearCallingIdentity();
5735 try {
5736 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5737 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005738 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005739 }
5740 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5741 } finally {
5742 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005743 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005744 }
5745
5746 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005747 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5748 *
5749 * @throws SecurityException if the caller does not have the required permission
5750 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005751 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005752 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07005753 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005754 }
5755
5756 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005757 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5758 * permission.
5759 *
5760 * @throws SecurityException if the caller does not have the required permission
5761 */
5762 private void enforceSendSmsPermission() {
5763 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5764 }
5765
5766 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005767 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005768 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005769 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005770 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005771 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005772 final long identity = Binder.clearCallingIdentity();
5773 try {
5774 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005775 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005776 if (componentName == null) {
5777 throw new SecurityException(
5778 "Caller not current active visual voicemail package[null]");
5779 }
5780 String vvmPackage = componentName.getPackageName();
5781 if (!callingPackage.equals(vvmPackage)) {
5782 throw new SecurityException("Caller not current active visual voicemail package["
5783 + vvmPackage + "]");
5784 }
5785 } finally {
5786 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005787 }
5788 }
5789
5790 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005791 * Return the application ID for the app type.
5792 *
5793 * @param subId the subscription ID that this request applies to.
5794 * @param appType the uicc app type.
5795 * @return Application ID for specificied app type, or null if no uicc.
5796 */
5797 @Override
5798 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005799 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005800 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005801
5802 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005803 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005804 if (phone == null) {
5805 return null;
5806 }
5807 String aid = null;
5808 try {
5809 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5810 .getApplicationByType(appType).getAid();
5811 } catch (Exception e) {
5812 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5813 }
5814 return aid;
5815 } finally {
5816 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005817 }
Youhan Wange64578a2016-05-02 15:32:42 -07005818 }
5819
Youhan Wang4001d252016-05-11 10:29:41 -07005820 /**
5821 * Return the Electronic Serial Number.
5822 *
5823 * @param subId the subscription ID that this request applies to.
5824 * @return ESN or null if error.
5825 */
5826 @Override
5827 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005828 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005829 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005830
5831 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005832 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005833 if (phone == null) {
5834 return null;
5835 }
5836 String esn = null;
5837 try {
5838 esn = phone.getEsn();
5839 } catch (Exception e) {
5840 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5841 }
5842 return esn;
5843 } finally {
5844 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005845 }
Youhan Wang4001d252016-05-11 10:29:41 -07005846 }
5847
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005848 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005849 * Return the Preferred Roaming List Version.
5850 *
5851 * @param subId the subscription ID that this request applies to.
5852 * @return PRLVersion or null if error.
5853 */
5854 @Override
5855 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005856 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005857 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005858
5859 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005860 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005861 if (phone == null) {
5862 return null;
5863 }
5864 String cdmaPrlVersion = null;
5865 try {
5866 cdmaPrlVersion = phone.getCdmaPrlVersion();
5867 } catch (Exception e) {
5868 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5869 }
5870 return cdmaPrlVersion;
5871 } finally {
5872 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005873 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005874 }
5875
5876 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005877 * Get snapshot of Telephony histograms
5878 * @return List of Telephony histograms
5879 * @hide
5880 */
5881 @Override
5882 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005883 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5884 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005885
5886 final long identity = Binder.clearCallingIdentity();
5887 try {
5888 return RIL.getTelephonyRILTimingHistograms();
5889 } finally {
5890 Binder.restoreCallingIdentity(identity);
5891 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005892 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005893
5894 /**
5895 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08005896 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
5897 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005898 * Require system privileges. In the future we may add this to carrier APIs.
5899 *
Michele Berionne482f8202018-11-27 18:57:59 -08005900 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005901 */
5902 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08005903 @TelephonyManager.SetCarrierRestrictionResult
5904 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005905 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005906 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005907
Michele Berionne482f8202018-11-27 18:57:59 -08005908 if (carrierRestrictionRules == null) {
5909 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08005910 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005911
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005912 final long identity = Binder.clearCallingIdentity();
5913 try {
Michele Berionne482f8202018-11-27 18:57:59 -08005914 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07005915 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005916 } finally {
5917 Binder.restoreCallingIdentity(identity);
5918 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005919 }
5920
5921 /**
5922 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08005923 * Get the allowed carrier list and the excluded carrier list, including the priority between
5924 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005925 * Require system privileges. In the future we may add this to carrier APIs.
5926 *
Michele Berionne482f8202018-11-27 18:57:59 -08005927 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07005928 */
5929 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08005930 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005931 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07005932 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005933
5934 final long identity = Binder.clearCallingIdentity();
5935 try {
Michele Berionne482f8202018-11-27 18:57:59 -08005936 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
5937 if (response instanceof CarrierRestrictionRules) {
5938 return (CarrierRestrictionRules) response;
5939 }
5940 // Response is an Exception of some kind,
5941 // which is signalled to the user as a NULL retval
5942 return null;
5943 } catch (Exception e) {
5944 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
5945 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005946 } finally {
5947 Binder.restoreCallingIdentity(identity);
5948 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005949 }
5950
fionaxu59545b42016-05-25 15:53:37 -07005951 /**
5952 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5953 * @param subId the subscription ID that this action applies to.
5954 * @param enabled control enable or disable metered apns.
5955 * {@hide}
5956 */
5957 @Override
5958 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5959 enforceModifyPermission();
5960 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005961
5962 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005963 if (phone == null) {
5964 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5965 return;
5966 }
5967 try {
5968 phone.carrierActionSetMeteredApnsEnabled(enabled);
5969 } catch (Exception e) {
5970 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005971 } finally {
5972 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005973 }
5974 }
5975
5976 /**
5977 * Action set from carrier signalling broadcast receivers to enable/disable radio
5978 * @param subId the subscription ID that this action applies to.
5979 * @param enabled control enable or disable radio.
5980 * {@hide}
5981 */
5982 @Override
5983 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5984 enforceModifyPermission();
5985 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005986
5987 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005988 if (phone == null) {
5989 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5990 return;
5991 }
5992 try {
5993 phone.carrierActionSetRadioEnabled(enabled);
5994 } catch (Exception e) {
5995 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005996 } finally {
5997 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005998 }
5999 }
6000
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006001 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006002 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6003 * network status based on which carrier apps could apply actions accordingly,
6004 * enable/disable default url handler for example.
6005 *
6006 * @param subId the subscription ID that this action applies to.
6007 * @param report control start/stop reporting the default network status.
6008 * {@hide}
6009 */
6010 @Override
6011 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6012 enforceModifyPermission();
6013 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006014
6015 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006016 if (phone == null) {
6017 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6018 return;
6019 }
6020 try {
6021 phone.carrierActionReportDefaultNetworkStatus(report);
6022 } catch (Exception e) {
6023 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006024 } finally {
6025 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006026 }
6027 }
6028
6029 /**
fionaxud9622282017-07-17 17:51:30 -07006030 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6031 * @param subId the subscription ID that this action applies to.
6032 * {@hide}
6033 */
6034 @Override
6035 public void carrierActionResetAll(int subId) {
6036 enforceModifyPermission();
6037 final Phone phone = getPhone(subId);
6038 if (phone == null) {
6039 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6040 return;
6041 }
6042 try {
6043 phone.carrierActionResetAll();
6044 } catch (Exception e) {
6045 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6046 }
6047 }
6048
6049 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006050 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6051 * bug report is being generated.
6052 */
6053 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006054 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006055 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6056 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006057 writer.println("Permission Denial: can't dump Phone from pid="
6058 + Binder.getCallingPid()
6059 + ", uid=" + Binder.getCallingUid()
6060 + "without permission "
6061 + android.Manifest.permission.DUMP);
6062 return;
6063 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006064 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006065 }
Jack Yueb89b242016-06-22 13:27:47 -07006066
Brad Ebingerdac2f002018-04-03 15:17:52 -07006067 @Override
6068 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6069 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6070 throws RemoteException {
6071 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
6072 }
6073
Jack Yueb89b242016-06-22 13:27:47 -07006074 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006075 * Get aggregated video call data usage since boot.
6076 *
6077 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6078 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006079 * {@hide}
6080 */
6081 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006082 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006083 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6084 null);
6085
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006086 final long identity = Binder.clearCallingIdentity();
6087 try {
6088 // NetworkStatsService keeps tracking the active network interface and identity. It
6089 // records the delta with the corresponding network identity.
6090 // We just return the total video call data usage snapshot since boot.
6091 Phone phone = getPhone(subId);
6092 if (phone != null) {
6093 return phone.getVtDataUsage(perUidStats);
6094 }
6095 return null;
6096 } finally {
6097 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006098 }
Jack Yueb89b242016-06-22 13:27:47 -07006099 }
Jack Yu75ab2952016-07-08 14:29:33 -07006100
6101 /**
6102 * Policy control of data connection. Usually used when data limit is passed.
6103 * @param enabled True if enabling the data, otherwise disabling.
6104 * @param subId Subscription index
6105 * {@hide}
6106 */
6107 @Override
6108 public void setPolicyDataEnabled(boolean enabled, int subId) {
6109 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006110
6111 final long identity = Binder.clearCallingIdentity();
6112 try {
6113 Phone phone = getPhone(subId);
6114 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006115 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006116 }
6117 } finally {
6118 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006119 }
6120 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006121
6122 /**
6123 * Get Client request stats
6124 * @return List of Client Request Stats
6125 * @hide
6126 */
6127 @Override
6128 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006129 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006130 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006131 return null;
6132 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006133 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006134
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006135 final long identity = Binder.clearCallingIdentity();
6136 try {
6137 if (phone != null) {
6138 return phone.getClientRequestStats();
6139 }
6140
6141 return null;
6142 } finally {
6143 Binder.restoreCallingIdentity(identity);
6144 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006145 }
6146
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006147 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006148 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006149 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006150 }
Jack Yueb4124c2017-02-16 15:32:43 -08006151
6152 /**
Grace Chen70990072017-03-24 17:21:30 -07006153 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006154 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006155 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006156 * @param state State of SIM (power down, power up, pass through)
6157 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6158 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6159 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006160 *
6161 **/
6162 @Override
Grace Chen70990072017-03-24 17:21:30 -07006163 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006164 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006165 Phone phone = PhoneFactory.getPhone(slotIndex);
6166
vagdeviaf9a5b92018-08-15 16:01:53 -07006167 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6168
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006169 final long identity = Binder.clearCallingIdentity();
6170 try {
6171 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006172 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006173 }
6174 } finally {
6175 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006176 }
6177 }
Shuo Qiandd210312017-04-12 22:11:33 +00006178
Tyler Gunn65d45c22017-06-05 11:22:26 -07006179 private boolean isUssdApiAllowed(int subId) {
6180 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006181 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006182 if (configManager == null) {
6183 return false;
6184 }
6185 PersistableBundle pb = configManager.getConfigForSubId(subId);
6186 if (pb == null) {
6187 return false;
6188 }
6189 return pb.getBoolean(
6190 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6191 }
6192
Shuo Qiandd210312017-04-12 22:11:33 +00006193 /**
6194 * Check if phone is in emergency callback mode
6195 * @return true if phone is in emergency callback mode
6196 * @param subId sub id
6197 */
goneil9c5f4872017-12-05 14:07:56 -08006198 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006199 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006200 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006201 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006202
6203 final long identity = Binder.clearCallingIdentity();
6204 try {
6205 if (phone != null) {
6206 return phone.isInEcm();
6207 } else {
6208 return false;
6209 }
6210 } finally {
6211 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006212 }
6213 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006214
6215 /**
6216 * Get the current signal strength information for the given subscription.
6217 * Because this information is not updated when the device is in a low power state
6218 * it should not be relied-upon to be current.
6219 * @param subId Subscription index
6220 * @return the most recent cached signal strength info from the modem
6221 */
6222 @Override
6223 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006224 final long identity = Binder.clearCallingIdentity();
6225 try {
6226 Phone p = getPhone(subId);
6227 if (p == null) {
6228 return null;
6229 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006230
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006231 return p.getSignalStrength();
6232 } finally {
6233 Binder.restoreCallingIdentity(identity);
6234 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006235 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006236
Pengquan Meng77b7f132018-08-22 14:49:57 -07006237 /**
Chen Xuf792fd62018-10-17 17:54:36 +00006238 * Get the current modem radio state for the given slot.
6239 * @param slotIndex slot index.
6240 * @param callingPackage the name of the package making the call.
6241 * @return the current radio power state from the modem
6242 */
6243 @Override
6244 public int getRadioPowerState(int slotIndex, String callingPackage) {
6245 Phone phone = PhoneFactory.getPhone(slotIndex);
6246 if (phone != null) {
6247 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6248 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
6249 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6250 }
6251
6252 final long identity = Binder.clearCallingIdentity();
6253 try {
6254 return phone.getRadioPowerState();
6255 } finally {
6256 Binder.restoreCallingIdentity(identity);
6257 }
6258 }
6259 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6260 }
6261
6262 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07006263 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6264 *
6265 * <p>Requires one of the following permissions:
6266 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6267 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6268 * privileges.
6269 *
6270 * @param subId subscription id
6271 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6272 * {@code false}.
6273 */
6274 @Override
6275 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006276 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6277 null /* message */);
6278
Pengquan Menga1bb6272018-09-06 09:59:22 -07006279 boolean isEnabled = false;
6280 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07006281 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006282 Phone phone = getPhone(subId);
6283 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006284 } catch (Exception e) {
6285 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6286 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07006287 } finally {
6288 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006289 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006290 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006291 }
6292
6293
6294 /**
6295 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6296 *
6297 * <p> Requires permission:
6298 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6299 * privileges.
6300 *
6301 * @param subId subscription id
6302 * @param isEnabled {@code true} means enable, {@code false} means disable.
6303 */
6304 @Override
6305 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006306 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6307 mApp, subId, "setDataRoamingEnabled");
6308
Pengquan Menga1bb6272018-09-06 09:59:22 -07006309 final long identity = Binder.clearCallingIdentity();
6310 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006311 Phone phone = getPhone(subId);
6312 if (phone != null) {
6313 phone.setDataRoamingEnabled(isEnabled);
6314 }
6315 } finally {
6316 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006317 }
6318 }
6319
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006320 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006321 public boolean isManualNetworkSelectionAllowed(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006322 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6323 mApp, subId, "isManualNetworkSelectionAllowed");
6324
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006325 boolean isAllowed = true;
6326 final long identity = Binder.clearCallingIdentity();
6327 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006328 Phone phone = getPhone(subId);
6329 if (phone != null) {
6330 isAllowed = phone.isCspPlmnEnabled();
6331 }
6332 } finally {
6333 Binder.restoreCallingIdentity(identity);
6334 }
6335 return isAllowed;
6336 }
6337
6338 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006339 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006340 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08006341 try {
6342 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07006343 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08006344 } catch (SecurityException e) {
6345 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6346 // has carrier privileges on an active UICC
6347 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6348 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006349 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08006350 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006351 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006352
6353 final long identity = Binder.clearCallingIdentity();
6354 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006355 UiccController uiccController = UiccController.getInstance();
6356 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07006357 if (hasReadPermission) {
6358 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006359 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07006360
6361 // Remove private info if the caller doesn't have access
6362 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6363 for (UiccCardInfo cardInfo : cardInfos) {
6364 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6365 // is available
6366 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
6367 if (card == null || card.getUiccProfile() == null) {
6368 // assume no access if the card or profile is unavailable
6369 filteredInfos.add(cardInfo.getUnprivileged());
6370 continue;
6371 }
6372 UiccProfile profile = card.getUiccProfile();
6373 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6374 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6375 filteredInfos.add(cardInfo);
6376 } else {
6377 filteredInfos.add(cardInfo.getUnprivileged());
6378 }
6379 }
6380 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08006381 } finally {
6382 Binder.restoreCallingIdentity(identity);
6383 }
6384 }
6385
6386 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006387 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006388 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006389
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006390 final long identity = Binder.clearCallingIdentity();
6391 try {
6392 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6393 if (slots == null) {
6394 Rlog.i(LOG_TAG, "slots is null.");
6395 return null;
6396 }
6397
6398 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6399 for (int i = 0; i < slots.length; i++) {
6400 UiccSlot slot = slots[i];
6401 if (slot == null) {
6402 continue;
6403 }
6404
Jordan Liu7be7e652019-05-06 18:55:02 +00006405 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006406 UiccCard card = slot.getUiccCard();
6407 if (card != null) {
6408 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00006409 } else {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006410 cardId = slot.getIccId();
6411 }
6412
6413 int cardState = 0;
6414 switch (slot.getCardState()) {
6415 case CARDSTATE_ABSENT:
6416 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6417 break;
6418 case CARDSTATE_PRESENT:
6419 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6420 break;
6421 case CARDSTATE_ERROR:
6422 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6423 break;
6424 case CARDSTATE_RESTRICTED:
6425 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6426 break;
6427 default:
6428 break;
6429
6430 }
6431
6432 infos[i] = new UiccSlotInfo(
6433 slot.isActive(),
6434 slot.isEuicc(),
6435 cardId,
6436 cardState,
6437 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08006438 slot.isExtendedApduSupported(),
6439 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006440 }
6441 return infos;
6442 } finally {
6443 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006444 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006445 }
6446
6447 @Override
6448 public boolean switchSlots(int[] physicalSlots) {
6449 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006450
6451 final long identity = Binder.clearCallingIdentity();
6452 try {
6453 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6454 } finally {
6455 Binder.restoreCallingIdentity(identity);
6456 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006457 }
Jack Yu4c988042018-02-27 15:30:01 -08006458
6459 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006460 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006461 final long identity = Binder.clearCallingIdentity();
6462 try {
6463 return UiccController.getInstance().getCardIdForDefaultEuicc();
6464 } finally {
6465 Binder.restoreCallingIdentity(identity);
6466 }
6467 }
6468
6469 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006470 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6471 enforceModifyPermission();
6472 final Phone phone = getPhone(subId);
6473 if (phone == null) {
6474 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6475 return;
6476 }
6477
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006478 final long identity = Binder.clearCallingIdentity();
6479 try {
6480 phone.setRadioIndicationUpdateMode(filters, mode);
6481 } finally {
6482 Binder.restoreCallingIdentity(identity);
6483 }
Jack Yu4c988042018-02-27 15:30:01 -08006484 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006485
6486 /**
goneil47ffb6e2018-04-06 15:40:58 -07006487 * A test API to reload the UICC profile.
6488 *
6489 * <p>Requires that the calling app has permission
6490 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6491 * @hide
6492 */
6493 @Override
6494 public void refreshUiccProfile(int subId) {
6495 enforceModifyPermission();
6496
6497 final long identity = Binder.clearCallingIdentity();
6498 try {
6499 Phone phone = getPhone(subId);
6500 if (phone == null) {
6501 return;
6502 }
6503 UiccCard uiccCard = phone.getUiccCard();
6504 if (uiccCard == null) {
6505 return;
6506 }
6507 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6508 if (uiccProfile == null) {
6509 return;
6510 }
6511 uiccProfile.refresh();
6512 } finally {
6513 Binder.restoreCallingIdentity(identity);
6514 }
6515 }
6516
6517 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006518 * Returns false if the mobile data is disabled by default, otherwise return true.
6519 */
6520 private boolean getDefaultDataEnabled() {
6521 return "true".equalsIgnoreCase(
6522 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
6523 }
6524
6525 /**
6526 * Returns true if the data roaming is enabled by default, i.e the system property
6527 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
6528 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
6529 */
6530 private boolean getDefaultDataRoamingEnabled(int subId) {
6531 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006532 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006533 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
6534 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
6535 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
6536 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
6537 return isDataRoamingEnabled;
6538 }
6539
6540 /**
6541 * Returns the default network type for the given {@code subId}, if the default network type is
6542 * not set, return {@link Phone#PREFERRED_NT_MODE}.
6543 */
6544 private int getDefaultNetworkType(int subId) {
6545 return Integer.parseInt(
6546 TelephonyManager.getTelephonyProperty(
6547 mSubscriptionController.getPhoneId(subId),
6548 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
6549 String.valueOf(Phone.PREFERRED_NT_MODE)));
6550 }
fionaxua13278b2018-03-21 00:08:13 -07006551
6552 @Override
6553 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07006554 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07006555 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006556
6557 final long identity = Binder.clearCallingIdentity();
6558 try {
6559 final Phone phone = getPhone(subId);
6560 if (phone == null) {
6561 loge("setCarrierTestOverride fails with invalid subId: " + subId);
6562 return;
6563 }
chen xueaba88a2019-03-15 13:15:10 -07006564 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
6565 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006566 } finally {
6567 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006568 }
fionaxua13278b2018-03-21 00:08:13 -07006569 }
6570
6571 @Override
6572 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006573 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006574
6575 final long identity = Binder.clearCallingIdentity();
6576 try {
6577 final Phone phone = getPhone(subId);
6578 if (phone == null) {
6579 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
6580 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
6581 }
6582 return phone.getCarrierIdListVersion();
6583 } finally {
6584 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006585 }
fionaxua13278b2018-03-21 00:08:13 -07006586 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07006587
6588 @Override
6589 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
6590 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6591 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
6592 return -1;
6593 }
6594
6595 final long identity = Binder.clearCallingIdentity();
6596 try {
6597 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
6598 } finally {
6599 Binder.restoreCallingIdentity(identity);
6600 }
6601 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006602
6603 @Override
6604 public int getCdmaRoamingMode(int subId) {
6605 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6606 mApp, subId, "getCdmaRoamingMode");
6607
6608 final long identity = Binder.clearCallingIdentity();
6609 try {
6610 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
6611 } finally {
6612 Binder.restoreCallingIdentity(identity);
6613 }
6614 }
6615
6616 @Override
6617 public boolean setCdmaRoamingMode(int subId, int mode) {
6618 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6619 mApp, subId, "setCdmaRoamingMode");
6620
6621 final long identity = Binder.clearCallingIdentity();
6622 try {
6623 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
6624 } finally {
6625 Binder.restoreCallingIdentity(identity);
6626 }
6627 }
6628
6629 @Override
6630 public boolean setCdmaSubscriptionMode(int subId, int mode) {
6631 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6632 mApp, subId, "setCdmaSubscriptionMode");
6633
6634 final long identity = Binder.clearCallingIdentity();
6635 try {
6636 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
6637 } finally {
6638 Binder.restoreCallingIdentity(identity);
6639 }
6640 }
Makoto Onukida3bf792018-09-18 16:06:29 -07006641
6642 private void ensureUserRunning(int userId) {
6643 if (!mUserManager.isUserRunning(userId)) {
6644 throw new IllegalStateException("User " + userId + " does not exist or not running");
6645 }
6646 }
6647
6648 /**
6649 * Returns a list of SMS apps on a given user.
6650 *
6651 * Only the shell user (UID 2000 or 0) can call it.
6652 * Target user must be running.
6653 */
6654 @Override
6655 public String[] getSmsApps(int userId) {
6656 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
6657 ensureUserRunning(userId);
6658
6659 final Collection<SmsApplicationData> apps =
6660 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
6661
6662 String[] ret = new String[apps.size()];
6663 int i = 0;
6664 for (SmsApplicationData app : apps) {
6665 ret[i++] = app.mPackageName;
6666 }
6667 return ret;
6668 }
6669
6670 /**
6671 * Returns the default SMS app package name on a given user.
6672 *
6673 * Only the shell user (UID 2000 or 0) can call it.
6674 * Target user must be running.
6675 */
6676 @Override
6677 public String getDefaultSmsApp(int userId) {
6678 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
6679 ensureUserRunning(userId);
6680
6681 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
6682 /* updateIfNeeded= */ true, userId);
6683 return cn == null ? null : cn.getPackageName();
6684 }
6685
6686 /**
6687 * Set a package as the default SMS app on a given user.
6688 *
6689 * Only the shell user (UID 2000 or 0) can call it.
6690 * Target user must be running.
6691 */
6692 @Override
6693 public void setDefaultSmsApp(int userId, String packageName) {
6694 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
6695 ensureUserRunning(userId);
6696
6697 boolean found = false;
6698 for (String pkg : getSmsApps(userId)) {
6699 if (TextUtils.equals(packageName, pkg)) {
6700 found = true;
6701 break;
6702 }
6703 }
6704 if (!found) {
6705 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
6706 }
6707
6708 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
6709 }
sqianc5eccab2018-10-19 18:46:41 -07006710
6711 @Override
sqian8c685422019-02-22 15:55:18 -08006712 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
sqianc5eccab2018-10-19 18:46:41 -07006713 String callingPackage) {
sqian11b7a0e2018-12-05 18:48:28 -08006714 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
sqian8c685422019-02-22 15:55:18 -08006715 mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08006716 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6717 }
6718 final long identity = Binder.clearCallingIdentity();
6719 try {
sqian854d44b2018-12-12 16:48:18 -08006720 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
6721 for (Phone phone: PhoneFactory.getPhones()) {
6722 if (phone.getEmergencyNumberTracker() != null
6723 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
6724 emergencyNumberListInternal.put(
6725 phone.getSubId(),
6726 phone.getEmergencyNumberTracker().getEmergencyNumberList());
6727 }
sqian11b7a0e2018-12-05 18:48:28 -08006728 }
sqian854d44b2018-12-12 16:48:18 -08006729 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08006730 } finally {
6731 Binder.restoreCallingIdentity(identity);
6732 }
sqianc5eccab2018-10-19 18:46:41 -07006733 }
6734
6735 @Override
sqian8c685422019-02-22 15:55:18 -08006736 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006737 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08006738 if (!exactMatch) {
6739 TelephonyPermissions
6740 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08006741 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08006742 }
6743 final long identity = Binder.clearCallingIdentity();
6744 try {
sqian854d44b2018-12-12 16:48:18 -08006745 for (Phone phone: PhoneFactory.getPhones()) {
6746 if (phone.getEmergencyNumberTracker() != null
6747 && phone.getEmergencyNumberTracker() != null) {
6748 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
6749 number, exactMatch)) {
6750 return true;
sqian11b7a0e2018-12-05 18:48:28 -08006751 }
6752 }
sqian11b7a0e2018-12-05 18:48:28 -08006753 }
6754 return false;
6755 } finally {
6756 Binder.restoreCallingIdentity(identity);
6757 }
6758 }
6759
sqianf4ca7ed2019-01-15 18:32:07 -08006760 /**
6761 * Update emergency number list for test mode.
6762 */
6763 @Override
6764 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
6765 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6766 "updateEmergencyNumberListTestMode");
6767
6768 final long identity = Binder.clearCallingIdentity();
6769 try {
6770 for (Phone phone: PhoneFactory.getPhones()) {
6771 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6772 if (tracker != null) {
6773 tracker.executeEmergencyNumberTestModeCommand(action, num);
6774 }
6775 }
6776 } finally {
6777 Binder.restoreCallingIdentity(identity);
6778 }
6779 }
6780
6781 /**
6782 * Get the full emergency number list for test mode.
6783 */
6784 @Override
6785 public List<String> getEmergencyNumberListTestMode() {
6786 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6787 "getEmergencyNumberListTestMode");
6788
6789 final long identity = Binder.clearCallingIdentity();
6790 try {
6791 Set<String> emergencyNumbers = new HashSet<>();
6792 for (Phone phone: PhoneFactory.getPhones()) {
6793 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6794 if (tracker != null) {
6795 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
6796 emergencyNumbers.add(num.getNumber());
6797 }
6798 }
6799 }
6800 return new ArrayList<>(emergencyNumbers);
6801 } finally {
6802 Binder.restoreCallingIdentity(identity);
6803 }
6804 }
6805
chen xud6b45bd2018-10-30 22:27:10 -07006806 @Override
6807 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
6808 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
6809 Phone phone = getPhone(subId);
6810 if (phone == null) {
6811 return null;
6812 }
6813 final long identity = Binder.clearCallingIdentity();
6814 try {
6815 UiccProfile profile = UiccController.getInstance()
6816 .getUiccProfileForPhone(phone.getPhoneId());
6817 if (profile != null) {
6818 return profile.getCertsFromCarrierPrivilegeAccessRules();
6819 }
6820 } finally {
6821 Binder.restoreCallingIdentity(identity);
6822 }
6823 return null;
6824 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08006825
6826 /**
6827 * Enable or disable a modem stack.
6828 */
6829 @Override
6830 public boolean enableModemForSlot(int slotIndex, boolean enable) {
6831 enforceModifyPermission();
6832
6833 final long identity = Binder.clearCallingIdentity();
6834 try {
6835 Phone phone = PhoneFactory.getPhone(slotIndex);
6836 if (phone == null) {
6837 return false;
6838 } else {
6839 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
6840 }
6841 } finally {
6842 Binder.restoreCallingIdentity(identity);
6843 }
6844 }
Michelecea4cf22018-12-21 15:00:11 -08006845
Malcolm Chen4bcd9822019-03-27 18:34:05 -07006846 /**
6847 * Whether a modem stack is enabled or not.
6848 */
6849 @Override
6850 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage) {
6851 Phone phone = PhoneFactory.getPhone(slotIndex);
6852 if (phone == null) return false;
6853
6854 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6855 mApp, phone.getSubId(), callingPackage, "isModemEnabledForSlot")) {
6856 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6857 }
6858
6859 final long identity = Binder.clearCallingIdentity();
6860 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07006861 try {
6862 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
6863 } catch (NoSuchElementException ex) {
6864 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
6865 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07006866 } finally {
6867 Binder.restoreCallingIdentity(identity);
6868 }
6869 }
6870
Michelecea4cf22018-12-21 15:00:11 -08006871 @Override
Michele0ea7d782019-03-19 14:58:42 -07006872 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08006873 enforceModifyPermission();
6874
6875 final long identity = Binder.clearCallingIdentity();
6876 try {
6877 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07006878 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08006879 .commit();
6880 } finally {
6881 Binder.restoreCallingIdentity(identity);
6882 }
6883 }
6884
6885 @Override
Michele0ea7d782019-03-19 14:58:42 -07006886 @TelephonyManager.IsMultiSimSupportedResult
6887 public int isMultiSimSupported(String callingPackage) {
Michele4245e952019-02-04 11:36:23 -08006888 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Michele0ea7d782019-03-19 14:58:42 -07006889 getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) {
6890 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08006891 }
Michelecea4cf22018-12-21 15:00:11 -08006892
6893 final long identity = Binder.clearCallingIdentity();
6894 try {
Michele0ea7d782019-03-19 14:58:42 -07006895 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08006896 } finally {
6897 Binder.restoreCallingIdentity(identity);
6898 }
6899 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006900
Michele0ea7d782019-03-19 14:58:42 -07006901 @TelephonyManager.IsMultiSimSupportedResult
6902 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08006903 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
6904 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
6905 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07006906 loge("isMultiSimSupportedInternal: requires at least 2 cards");
6907 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006908 }
6909 // Check if the hardware supports multisim functionality. If usage of multisim is not
6910 // supported by the modem, indicate that it is restricted.
6911 PhoneCapability staticCapability =
6912 mPhoneConfigurationManager.getStaticPhoneCapability();
6913 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07006914 loge("isMultiSimSupportedInternal: no static configuration available");
6915 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006916 }
6917 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07006918 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
6919 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006920 }
6921 // Check if support of multiple SIMs is restricted by carrier
6922 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07006923 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08006924 }
6925
Michele0ea7d782019-03-19 14:58:42 -07006926 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08006927 }
6928
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006929 /**
6930 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08006931 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
6932 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
6933 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006934 * @param numOfSims number of active sims we want to switch to
6935 */
6936 @Override
6937 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08006938 if (numOfSims == 1) {
6939 enforceModifyPermission();
6940 } else {
6941 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6942 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
6943 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006944 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08006945
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006946 try {
Michele30b57b22019-03-01 12:01:14 -08006947 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07006948 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08006949 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
6950 return;
6951 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006952 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
6953 } finally {
6954 Binder.restoreCallingIdentity(identity);
6955 }
6956 }
6957
6958 /**
chen xub4baa772019-04-03 10:23:41 -07006959 * Get whether making changes to modem configurations will trigger reboot.
6960 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08006961 */
6962 @Override
chen xub4baa772019-04-03 10:23:41 -07006963 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage) {
6964 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6965 mApp, subId, callingPackage, "doesSwitchMultiSimConfigTriggerReboot")) {
6966 return false;
6967 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08006968 final long identity = Binder.clearCallingIdentity();
6969 try {
6970 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
6971 } finally {
6972 Binder.restoreCallingIdentity(identity);
6973 }
6974 }
6975
Nathan Harold29f5f052019-02-15 13:41:57 -08006976 private void updateModemStateMetrics() {
6977 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
6978 // TODO: check the state for each modem if the api is ready.
6979 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
6980 }
6981
Pengquan Meng3889a572019-01-23 11:16:29 -08006982 @Override
6983 public int[] getSlotsMapping() {
6984 enforceReadPrivilegedPermission("getSlotsMapping");
6985
6986 final long identity = Binder.clearCallingIdentity();
6987 try {
6988 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
6989 // All logical slots should have a mapping to a physical slot.
6990 int[] logicalSlotsMapping = new int[phoneCount];
6991 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
6992 for (int i = 0; i < slotInfos.length; i++) {
6993 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
6994 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
6995 }
6996 }
6997 return logicalSlotsMapping;
6998 } finally {
6999 Binder.restoreCallingIdentity(identity);
7000 }
7001 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007002
7003 /**
7004 * Get the IRadio HAL Version
7005 */
7006 @Override
7007 public int getRadioHalVersion() {
7008 Phone phone = getDefaultPhone();
7009 if (phone == null) return -1;
7010 HalVersion hv = phone.getHalVersion();
7011 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7012 return hv.major * 100 + hv.minor;
7013 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007014
7015 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007016 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7017 * corresponding network requests on a subId.
7018 *
7019 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007020 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007021 * 2) APN is un-metered for this subscription, or
7022 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
7023 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on.
7024 *
7025 * @return whether data is allowed for a apn type.
7026 *
7027 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007028 */
7029 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007030 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007031 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Malcolm Chene5ad5792019-04-18 13:51:02 -07007032 mApp, subId, callingPackage, "isDataEnabledForApn")) {
7033 throw new SecurityException("Needs READ_PHONE_STATE for isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007034 }
7035
7036 // Now that all security checks passes, perform the operation as ourselves.
7037 final long identity = Binder.clearCallingIdentity();
7038 try {
7039 Phone phone = getPhone(subId);
7040 if (phone == null) return false;
7041
7042 boolean isMetered = ApnSettingUtils.isMeteredApnType(ApnSetting.getApnTypeString(
Malcolm Chene5ad5792019-04-18 13:51:02 -07007043 apnType), phone);
7044 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7045 } finally {
7046 Binder.restoreCallingIdentity(identity);
7047 }
7048 }
7049
7050 @Override
7051 public boolean isApnMetered(int apnType, int subId) {
7052 enforceReadPrivilegedPermission("isApnMetered");
7053
7054 // Now that all security checks passes, perform the operation as ourselves.
7055 final long identity = Binder.clearCallingIdentity();
7056 try {
7057 Phone phone = getPhone(subId);
7058 if (phone == null) return true; // By default return true.
7059
7060 return ApnSettingUtils.isMeteredApnType(ApnSetting.getApnTypeString(
7061 apnType), phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007062 } finally {
7063 Binder.restoreCallingIdentity(identity);
7064 }
7065 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007066
7067 @Override
7068 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
7069 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
7070 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
7071 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
7072 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
7073 }
7074 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
7075 Intent intent = new Intent();
7076 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
7077 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7078 // Bring up choose default SMS subscription dialog right now
7079 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
7080 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
7081 mApp.startActivity(intent);
7082 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007083}