blob: a476fee4e5a9f0c9e3b9fa517631f45365398288 [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
Tyler Gunn7bcdc742019-10-04 15:56:59 -070021import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070022import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
23
Ta-wei Yen30a69c82016-12-27 14:52:32 -080024import android.Manifest.permission;
Tyler Gunnf70ed162019-04-03 15:28:53 -070025import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070026import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080027import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070028import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070029import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070030import android.content.Context;
31import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070032import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070033import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070034import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080035import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070036import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070037import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070038import android.net.Uri;
39import android.os.AsyncResult;
40import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080041import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070042import android.os.Bundle;
43import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070044import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070045import android.os.Looper;
46import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070047import android.os.Messenger;
Tyler Gunn65d45c22017-06-05 11:22:26 -070048import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080049import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070050import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070051import android.os.ServiceManager;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070052import android.os.ServiceSpecificException;
Brad Ebingerdac2f002018-04-03 15:17:52 -070053import android.os.ShellCallback;
Pengquan Meng85728fb2018-03-12 16:31:21 -070054import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070056import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070057import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070058import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080059import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070060import android.provider.Telephony;
Santos Cordon7a1885b2015-02-03 11:15:19 -080061import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080062import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070063import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070064import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080065import android.telephony.CarrierRestrictionRules;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070066import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070067import android.telephony.CellInfoGsm;
68import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070069import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070070import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070071import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070072import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080073import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070074import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080075import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070076import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080077import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080078import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070079import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080080import android.telephony.RadioAccessSpecifier;
Tyler Gunn65d45c22017-06-05 11:22:26 -070081import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070082import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080083import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080084import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080085import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070086import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070087import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080088import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080089import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000090import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070091import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070092import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070093import android.telephony.cdma.CdmaCellLocation;
Jack Yub5d8f642018-11-26 11:20:48 -080094import android.telephony.data.ApnSetting;
Jack Yu41407ee2019-05-13 16:54:09 -070095import android.telephony.data.ApnSetting.ApnType;
Jack Yub5d8f642018-11-26 11:20:48 -080096import android.telephony.emergency.EmergencyNumber;
Nathan Harold3ff88932018-08-14 10:19:49 -070097import android.telephony.gsm.GsmCellLocation;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070098import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -080099import android.telephony.ims.ProvisioningManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700100import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800101import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700102import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800103import android.telephony.ims.aidl.IImsMmTelFeature;
104import android.telephony.ims.aidl.IImsRcsFeature;
105import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700106import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800107import android.telephony.ims.feature.MmTelFeature;
108import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800109import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700110import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800111import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700112import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800113import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800114import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800115
Andrew Lee312e8172014-10-23 17:01:36 -0700116import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800117import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700118import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700119import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700120import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800121import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700122import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700123import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700124import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800125import com.android.internal.telephony.HalVersion;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700126import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800127import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700128import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800129import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700130import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100131import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700132import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700133import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700134import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700135import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800136import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700137import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700138import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700139import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700140import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700141import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700142import com.android.internal.telephony.ServiceStateTracker;
Makoto Onukida3bf792018-09-18 16:06:29 -0700143import com.android.internal.telephony.SmsApplication;
144import com.android.internal.telephony.SmsApplication.SmsApplicationData;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700145import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700146import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800147import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800148import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700149import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800150import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700151import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800152import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700153import com.android.internal.telephony.imsphone.ImsPhone;
154import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800155import com.android.internal.telephony.metrics.TelephonyMetrics;
Taesu Leef8fbed92019-10-07 18:47:02 +0900156import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700157import com.android.internal.telephony.uicc.IccIoResult;
158import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800159import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700160import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800161import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700162import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800163import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000164import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700165import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800166import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700167import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700168import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800169import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700170import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700171import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800172
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700173import java.io.FileDescriptor;
174import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700175import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800176import java.util.Arrays;
Makoto Onukida3bf792018-09-18 16:06:29 -0700177import java.util.Collection;
sqian11b7a0e2018-12-05 18:48:28 -0800178import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800179import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800180import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100181import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800182import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700183import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800184import java.util.Set;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700185
186/**
187 * Implementation of the ITelephony interface.
188 */
Santos Cordon117fee72014-05-16 17:56:12 -0700189public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700190 private static final String LOG_TAG = "PhoneInterfaceManager";
191 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
192 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800193 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700194
195 // Message codes used with mMainThreadHandler
196 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700197 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
198 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700199 private static final int CMD_OPEN_CHANNEL = 9;
200 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
201 private static final int CMD_CLOSE_CHANNEL = 11;
202 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800203 private static final int CMD_NV_READ_ITEM = 13;
204 private static final int EVENT_NV_READ_ITEM_DONE = 14;
205 private static final int CMD_NV_WRITE_ITEM = 15;
206 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
207 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
208 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700209 private static final int CMD_RESET_MODEM_CONFIG = 19;
210 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800211 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
212 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
213 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
214 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800215 private static final int CMD_SEND_ENVELOPE = 25;
216 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000217 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
218 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700219 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
220 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
221 private static final int CMD_EXCHANGE_SIM_IO = 31;
222 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800223 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
224 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700225 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
226 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700227 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
228 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700229 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
230 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
231 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
232 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700233 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
234 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
235 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
236 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700237 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800238 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
239 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000240 private static final int CMD_SWITCH_SLOTS = 50;
241 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700242 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
243 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
244 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
245 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
246 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
247 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
248 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
249 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700250 private static final int CMD_GET_ALL_CELL_INFO = 60;
251 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
252 private static final int CMD_GET_CELL_LOCATION = 62;
253 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700254 private static final int CMD_MODEM_REBOOT = 64;
255 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700256 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
257 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800258 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
259 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700260 private static final int CMD_GET_MODEM_STATUS = 70;
261 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700262
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800263 // Parameters of select command.
264 private static final int SELECT_COMMAND = 0xA4;
265 private static final int SELECT_P1 = 0x04;
266 private static final int SELECT_P2 = 0;
267 private static final int SELECT_P3 = 0x10;
268
Pengquan Meng85728fb2018-03-12 16:31:21 -0700269 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
270 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
271 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
272
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700273 /** The singleton instance. */
274 private static PhoneInterfaceManager sInstance;
275
Wink Saville3ab207e2014-11-20 13:07:20 -0800276 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800277 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700278 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800279 private AppOpsManager mAppOps;
280 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800281 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800282 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700283 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700284
Derek Tan97ebb422014-09-05 16:55:38 -0700285 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
286 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800287 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800288 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700289
Michelecea4cf22018-12-21 15:00:11 -0800290 // String to store multi SIM allowed
291 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
292
Derek Tan740e1672017-06-27 14:56:27 -0700293 // The AID of ISD-R.
294 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
295
yinxub1bed742017-04-17 11:45:04 -0700296 private NetworkScanRequestTracker mNetworkScanRequestTracker;
297
David Kelly5e06a7f2018-03-12 14:10:59 +0000298 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
299 private static final int MANUFACTURER_CODE_LENGTH = 8;
300
Derek Tan89e89d42014-07-08 17:00:10 -0700301 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700302 * A request object to use for transmitting data to an ICC.
303 */
304 private static final class IccAPDUArgument {
305 public int channel, cla, command, p1, p2, p3;
306 public String data;
307
308 public IccAPDUArgument(int channel, int cla, int command,
309 int p1, int p2, int p3, String data) {
310 this.channel = channel;
311 this.cla = cla;
312 this.command = command;
313 this.p1 = p1;
314 this.p2 = p2;
315 this.p3 = p3;
316 this.data = data;
317 }
318 }
319
320 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700321 * A request object to use for transmitting data to an ICC.
322 */
323 private static final class ManualNetworkSelectionArgument {
324 public OperatorInfo operatorInfo;
325 public boolean persistSelection;
326
327 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
328 this.operatorInfo = operatorInfo;
329 this.persistSelection = persistSelection;
330 }
331 }
332
333 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700334 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
335 * request after sending. The main thread will notify the request when it is complete.
336 */
337 private static final class MainThreadRequest {
338 /** The argument to use for the request */
339 public Object argument;
340 /** The result of the request that is run on the main thread */
341 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800342 // The subscriber id that this request applies to. Defaults to
343 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
344 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700345
Nathan Harold92bed182018-10-12 18:16:49 -0700346 // In cases where subId is unavailable, the caller needs to specify the phone.
347 public Phone phone;
348
vagdeviaf9a5b92018-08-15 16:01:53 -0700349 public WorkSource workSource;
350
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700351 public MainThreadRequest(Object argument) {
352 this.argument = argument;
353 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800354
Nathan Harold92bed182018-10-12 18:16:49 -0700355 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
356 this.argument = argument;
357 if (phone != null) {
358 this.phone = phone;
359 }
360 this.workSource = workSource;
361 }
362
vagdeviaf9a5b92018-08-15 16:01:53 -0700363 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800364 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800365 if (subId != null) {
366 this.subId = subId;
367 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700368 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800369 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700370 }
371
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800372 private static final class IncomingThirdPartyCallArgs {
373 public final ComponentName component;
374 public final String callId;
375 public final String callerDisplayName;
376
377 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
378 String callerDisplayName) {
379 this.component = component;
380 this.callId = callId;
381 this.callerDisplayName = callerDisplayName;
382 }
383 }
384
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700385 /**
386 * A handler that processes messages on the main thread in the phone process. Since many
387 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
388 * inbound binder threads to the main thread in the phone process. The Binder thread
389 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
390 * on, which will be notified when the operation completes and will contain the result of the
391 * request.
392 *
393 * <p>If a MainThreadRequest object is provided in the msg.obj field,
394 * note that request.result must be set to something non-null for the calling thread to
395 * unblock.
396 */
397 private final class MainThreadHandler extends Handler {
398 @Override
399 public void handleMessage(Message msg) {
400 MainThreadRequest request;
401 Message onCompleted;
402 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800403 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700404 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800405 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700406
407 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700408 case CMD_HANDLE_USSD_REQUEST: {
409 request = (MainThreadRequest) msg.obj;
410 final Phone phone = getPhoneFromRequest(request);
411 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
412 String ussdRequest = ussdObject.first;
413 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700414
Pengquan Menga1bb6272018-09-06 09:59:22 -0700415 if (!isUssdApiAllowed(request.subId)) {
416 // Carrier does not support use of this API, return failure.
417 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
418 UssdResponse response = new UssdResponse(ussdRequest, null);
419 Bundle returnData = new Bundle();
420 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
421 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700422
Pengquan Menga1bb6272018-09-06 09:59:22 -0700423 request.result = true;
424 notifyRequester(request);
425 return;
426 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700427
Pengquan Menga1bb6272018-09-06 09:59:22 -0700428 try {
429 request.result = phone != null
430 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
431 } catch (CallStateException cse) {
432 request.result = false;
433 }
434 // Wake up the requesting thread
435 notifyRequester(request);
436 break;
pkanwar32d516d2016-10-14 19:37:38 -0700437 }
438
Yorke Lee716f67e2015-06-17 15:39:16 -0700439 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700440 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700441 final Phone phone = getPhoneFromRequest(request);
442 request.result = phone != null ?
443 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
444 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700445 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700446 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700447 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700448 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700449
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700450 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700451 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700452 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800453 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700454 if (uiccCard == null) {
455 loge("iccTransmitApduLogicalChannel: No UICC");
456 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700457 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700458 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700459 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
460 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700461 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700462 iccArgument.channel, iccArgument.cla, iccArgument.command,
463 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700464 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700465 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700466 break;
467
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700468 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700469 ar = (AsyncResult) msg.obj;
470 request = (MainThreadRequest) ar.userObj;
471 if (ar.exception == null && ar.result != null) {
472 request.result = ar.result;
473 } else {
474 request.result = new IccIoResult(0x6F, 0, (byte[])null);
475 if (ar.result == null) {
476 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800477 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700478 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800479 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700480 } else {
481 loge("iccTransmitApduLogicalChannel: Unknown exception");
482 }
483 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700484 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700485 break;
486
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700487 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
488 request = (MainThreadRequest) msg.obj;
489 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800490 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700491 if (uiccCard == null) {
492 loge("iccTransmitApduBasicChannel: No UICC");
493 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700494 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700495 } else {
496 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
497 request);
498 uiccCard.iccTransmitApduBasicChannel(
499 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
500 iccArgument.p3, iccArgument.data, onCompleted);
501 }
502 break;
503
504 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
505 ar = (AsyncResult) msg.obj;
506 request = (MainThreadRequest) ar.userObj;
507 if (ar.exception == null && ar.result != null) {
508 request.result = ar.result;
509 } else {
510 request.result = new IccIoResult(0x6F, 0, (byte[])null);
511 if (ar.result == null) {
512 loge("iccTransmitApduBasicChannel: Empty response");
513 } else if (ar.exception instanceof CommandException) {
514 loge("iccTransmitApduBasicChannel: CommandException: " +
515 ar.exception);
516 } else {
517 loge("iccTransmitApduBasicChannel: Unknown exception");
518 }
519 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700520 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700521 break;
522
523 case CMD_EXCHANGE_SIM_IO:
524 request = (MainThreadRequest) msg.obj;
525 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800526 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700527 if (uiccCard == null) {
528 loge("iccExchangeSimIO: No UICC");
529 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700530 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700531 } else {
532 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
533 request);
534 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
535 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
536 iccArgument.data, onCompleted);
537 }
538 break;
539
540 case EVENT_EXCHANGE_SIM_IO_DONE:
541 ar = (AsyncResult) msg.obj;
542 request = (MainThreadRequest) ar.userObj;
543 if (ar.exception == null && ar.result != null) {
544 request.result = ar.result;
545 } else {
546 request.result = new IccIoResult(0x6f, 0, (byte[])null);
547 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700548 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700549 break;
550
Derek Tan4d5e5c12014-02-04 11:54:58 -0800551 case CMD_SEND_ENVELOPE:
552 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800553 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700554 if (uiccCard == null) {
555 loge("sendEnvelopeWithStatus: No UICC");
556 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700557 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700558 } else {
559 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
560 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
561 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800562 break;
563
564 case EVENT_SEND_ENVELOPE_DONE:
565 ar = (AsyncResult) msg.obj;
566 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700567 if (ar.exception == null && ar.result != null) {
568 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800569 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700570 request.result = new IccIoResult(0x6F, 0, (byte[])null);
571 if (ar.result == null) {
572 loge("sendEnvelopeWithStatus: Empty response");
573 } else if (ar.exception instanceof CommandException) {
574 loge("sendEnvelopeWithStatus: CommandException: " +
575 ar.exception);
576 } else {
577 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
578 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800579 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700580 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800581 break;
582
Shishir Agrawal566b7612013-10-28 14:41:00 -0700583 case CMD_OPEN_CHANNEL:
584 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800585 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800586 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700587 if (uiccCard == null) {
588 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800589 request.result = new IccOpenLogicalChannelResponse(-1,
590 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700591 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700592 } else {
593 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800594 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
595 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700596 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700597 break;
598
599 case EVENT_OPEN_CHANNEL_DONE:
600 ar = (AsyncResult) msg.obj;
601 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700602 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700603 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700604 int[] result = (int[]) ar.result;
605 int channelId = result[0];
606 byte[] selectResponse = null;
607 if (result.length > 1) {
608 selectResponse = new byte[result.length - 1];
609 for (int i = 1; i < result.length; ++i) {
610 selectResponse[i - 1] = (byte) result[i];
611 }
612 }
613 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700614 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700615 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700616 if (ar.result == null) {
617 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700618 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700619 if (ar.exception != null) {
620 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
621 }
622
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700623 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700624 if (ar.exception instanceof CommandException) {
625 CommandException.Error error =
626 ((CommandException) (ar.exception)).getCommandError();
627 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700628 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700629 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700630 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700631 }
632 }
633 openChannelResp = new IccOpenLogicalChannelResponse(
634 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700635 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700636 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700637 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700638 break;
639
640 case CMD_CLOSE_CHANNEL:
641 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800642 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700643 if (uiccCard == null) {
644 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900645 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700646 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700647 } else {
648 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
649 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
650 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700651 break;
652
653 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800654 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
655 break;
656
657 case CMD_NV_READ_ITEM:
658 request = (MainThreadRequest) msg.obj;
659 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800660 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
661 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800662 break;
663
664 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700665 ar = (AsyncResult) msg.obj;
666 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800667 if (ar.exception == null && ar.result != null) {
668 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700669 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800670 request.result = "";
671 if (ar.result == null) {
672 loge("nvReadItem: Empty response");
673 } else if (ar.exception instanceof CommandException) {
674 loge("nvReadItem: CommandException: " +
675 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700676 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800677 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700678 }
679 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700680 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700681 break;
682
Jake Hambye994d462014-02-03 13:10:13 -0800683 case CMD_NV_WRITE_ITEM:
684 request = (MainThreadRequest) msg.obj;
685 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
686 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800687 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700688 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800689 break;
690
691 case EVENT_NV_WRITE_ITEM_DONE:
692 handleNullReturnEvent(msg, "nvWriteItem");
693 break;
694
695 case CMD_NV_WRITE_CDMA_PRL:
696 request = (MainThreadRequest) msg.obj;
697 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800698 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800699 break;
700
701 case EVENT_NV_WRITE_CDMA_PRL_DONE:
702 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
703 break;
704
chen xu6dac5ab2018-10-26 17:39:23 -0700705 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800706 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700707 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800708 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800709 break;
710
chen xu6dac5ab2018-10-26 17:39:23 -0700711 case EVENT_RESET_MODEM_CONFIG_DONE:
712 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800713 break;
714
Jake Hamby7c27be32014-03-03 13:25:59 -0800715 case CMD_GET_PREFERRED_NETWORK_TYPE:
716 request = (MainThreadRequest) msg.obj;
717 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700718 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800719 break;
720
721 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
722 ar = (AsyncResult) msg.obj;
723 request = (MainThreadRequest) ar.userObj;
724 if (ar.exception == null && ar.result != null) {
725 request.result = ar.result; // Integer
726 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800727 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800728 if (ar.result == null) {
729 loge("getPreferredNetworkType: Empty response");
730 } else if (ar.exception instanceof CommandException) {
731 loge("getPreferredNetworkType: CommandException: " +
732 ar.exception);
733 } else {
734 loge("getPreferredNetworkType: Unknown exception");
735 }
736 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700737 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800738 break;
739
740 case CMD_SET_PREFERRED_NETWORK_TYPE:
741 request = (MainThreadRequest) msg.obj;
742 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
743 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700744 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800745 break;
746
747 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
748 handleNullReturnEvent(msg, "setPreferredNetworkType");
749 break;
750
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000751 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
752 request = (MainThreadRequest)msg.obj;
753 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800754 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000755 break;
756
757 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
758 ar = (AsyncResult)msg.obj;
759 request = (MainThreadRequest)ar.userObj;
760 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700761 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000762 break;
763
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800764 case CMD_SET_VOICEMAIL_NUMBER:
765 request = (MainThreadRequest) msg.obj;
766 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
767 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800768 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
769 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800770 break;
771
772 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
773 handleNullReturnEvent(msg, "setVoicemailNumber");
774 break;
775
Stuart Scott54788802015-03-30 13:18:01 -0700776 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
777 request = (MainThreadRequest) msg.obj;
778 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
779 request);
780 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
781 break;
782
783 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
784 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
785 break;
786
Shishir Agrawal302c8692015-06-19 13:49:39 -0700787 case CMD_PERFORM_NETWORK_SCAN:
788 request = (MainThreadRequest) msg.obj;
789 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
790 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
791 break;
792
793 case EVENT_PERFORM_NETWORK_SCAN_DONE:
794 ar = (AsyncResult) msg.obj;
795 request = (MainThreadRequest) ar.userObj;
796 CellNetworkScanResult cellScanResult;
797 if (ar.exception == null && ar.result != null) {
798 cellScanResult = new CellNetworkScanResult(
799 CellNetworkScanResult.STATUS_SUCCESS,
800 (List<OperatorInfo>) ar.result);
801 } else {
802 if (ar.result == null) {
803 loge("getCellNetworkScanResults: Empty response");
804 }
805 if (ar.exception != null) {
806 loge("getCellNetworkScanResults: Exception: " + ar.exception);
807 }
808 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
809 if (ar.exception instanceof CommandException) {
810 CommandException.Error error =
811 ((CommandException) (ar.exception)).getCommandError();
812 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
813 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
814 } else if (error == CommandException.Error.GENERIC_FAILURE) {
815 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
816 }
817 }
818 cellScanResult = new CellNetworkScanResult(errorCode, null);
819 }
820 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700821 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700822 break;
823
824 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
825 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700826 ManualNetworkSelectionArgument selArg =
827 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700828 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
829 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700830 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
831 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700832 break;
833
834 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700835 ar = (AsyncResult) msg.obj;
836 request = (MainThreadRequest) ar.userObj;
837 if (ar.exception == null) {
838 request.result = true;
839 } else {
840 request.result = false;
841 loge("setNetworkSelectionModeManual " + ar.exception);
842 }
843 notifyRequester(request);
844 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700845 break;
846
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700847 case CMD_GET_MODEM_ACTIVITY_INFO:
848 request = (MainThreadRequest) msg.obj;
849 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -0700850 if (defaultPhone != null) {
851 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
852 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700853 break;
854
855 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
856 ar = (AsyncResult) msg.obj;
857 request = (MainThreadRequest) ar.userObj;
858 if (ar.exception == null && ar.result != null) {
859 request.result = ar.result;
860 } else {
861 if (ar.result == null) {
862 loge("queryModemActivityInfo: Empty response");
863 } else if (ar.exception instanceof CommandException) {
864 loge("queryModemActivityInfo: CommandException: " +
865 ar.exception);
866 } else {
867 loge("queryModemActivityInfo: Unknown exception");
868 }
869 }
Amit Mahajand4766222016-01-28 15:28:28 -0800870 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
871 if (request.result == null) {
872 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
873 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700874 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700875 break;
876
Meng Wang1a7c35a2016-05-05 20:56:15 -0700877 case CMD_SET_ALLOWED_CARRIERS:
878 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -0800879 CarrierRestrictionRules argument =
880 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700881 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -0800882 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700883 break;
884
885 case EVENT_SET_ALLOWED_CARRIERS_DONE:
886 ar = (AsyncResult) msg.obj;
887 request = (MainThreadRequest) ar.userObj;
888 if (ar.exception == null && ar.result != null) {
889 request.result = ar.result;
890 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800891 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
892 if (ar.exception instanceof CommandException) {
893 loge("setAllowedCarriers: CommandException: " + ar.exception);
894 CommandException.Error error =
895 ((CommandException) (ar.exception)).getCommandError();
896 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
897 request.result =
898 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
899 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700900 } else {
901 loge("setAllowedCarriers: Unknown exception");
902 }
903 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700904 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700905 break;
906
907 case CMD_GET_ALLOWED_CARRIERS:
908 request = (MainThreadRequest) msg.obj;
909 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800910 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700911 break;
912
913 case EVENT_GET_ALLOWED_CARRIERS_DONE:
914 ar = (AsyncResult) msg.obj;
915 request = (MainThreadRequest) ar.userObj;
916 if (ar.exception == null && ar.result != null) {
917 request.result = ar.result;
918 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800919 request.result = new IllegalStateException(
920 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700921 if (ar.result == null) {
922 loge("getAllowedCarriers: Empty response");
923 } else if (ar.exception instanceof CommandException) {
924 loge("getAllowedCarriers: CommandException: " +
925 ar.exception);
926 } else {
927 loge("getAllowedCarriers: Unknown exception");
928 }
929 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700930 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700931 break;
932
Nathan Haroldb3014052017-01-25 15:57:32 -0800933 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
934 ar = (AsyncResult) msg.obj;
935 request = (MainThreadRequest) ar.userObj;
936 if (ar.exception == null && ar.result != null) {
937 request.result = ar.result;
938 } else {
939 request.result = new IllegalArgumentException(
940 "Failed to retrieve Forbidden Plmns");
941 if (ar.result == null) {
942 loge("getForbiddenPlmns: Empty response");
943 } else {
944 loge("getForbiddenPlmns: Unknown exception");
945 }
946 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700947 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800948 break;
949
950 case CMD_GET_FORBIDDEN_PLMNS:
951 request = (MainThreadRequest) msg.obj;
952 uiccCard = getUiccCardFromRequest(request);
953 if (uiccCard == null) {
954 loge("getForbiddenPlmns() UiccCard is null");
955 request.result = new IllegalArgumentException(
956 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700957 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800958 break;
959 }
960 Integer appType = (Integer) request.argument;
961 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
962 if (uiccApp == null) {
963 loge("getForbiddenPlmns() no app with specified type -- "
964 + appType);
965 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700966 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800967 break;
968 } else {
969 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
970 + " specified type -- " + appType);
971 }
972 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
973 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
974 onCompleted);
975 break;
976
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000977 case CMD_SWITCH_SLOTS:
978 request = (MainThreadRequest) msg.obj;
979 int[] physicalSlots = (int[]) request.argument;
980 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
981 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
982 break;
983
984 case EVENT_SWITCH_SLOTS_DONE:
985 ar = (AsyncResult) msg.obj;
986 request = (MainThreadRequest) ar.userObj;
987 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700988 notifyRequester(request);
989 break;
990 case CMD_GET_NETWORK_SELECTION_MODE:
991 request = (MainThreadRequest) msg.obj;
992 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
993 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
994 break;
995
996 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
997 ar = (AsyncResult) msg.obj;
998 request = (MainThreadRequest) ar.userObj;
999 if (ar.exception != null) {
1000 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1001 } else {
1002 int mode = ((int[]) ar.result)[0];
1003 if (mode == 0) {
1004 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1005 } else {
1006 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1007 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001008 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001009 notifyRequester(request);
1010 break;
1011 case CMD_GET_CDMA_ROAMING_MODE:
1012 request = (MainThreadRequest) msg.obj;
1013 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1014 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1015 break;
1016 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1017 ar = (AsyncResult) msg.obj;
1018 request = (MainThreadRequest) ar.userObj;
1019 if (ar.exception != null) {
1020 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1021 } else {
1022 request.result = ((int[]) ar.result)[0];
1023 }
1024 notifyRequester(request);
1025 break;
1026 case CMD_SET_CDMA_ROAMING_MODE:
1027 request = (MainThreadRequest) msg.obj;
1028 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1029 int mode = (int) request.argument;
1030 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1031 break;
1032 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1033 ar = (AsyncResult) msg.obj;
1034 request = (MainThreadRequest) ar.userObj;
1035 request.result = ar.exception == null;
1036 notifyRequester(request);
1037 break;
1038 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1039 request = (MainThreadRequest) msg.obj;
1040 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1041 int subscriptionMode = (int) request.argument;
1042 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1043 break;
1044 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1045 ar = (AsyncResult) msg.obj;
1046 request = (MainThreadRequest) ar.userObj;
1047 request.result = ar.exception == null;
1048 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001049 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001050 case CMD_GET_ALL_CELL_INFO:
1051 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001052 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001053 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001054 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001055 case EVENT_GET_ALL_CELL_INFO_DONE:
1056 ar = (AsyncResult) msg.obj;
1057 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001058 // If a timeout occurs, the response will be null
1059 request.result = (ar.exception == null && ar.result != null)
1060 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001061 synchronized (request) {
1062 request.notifyAll();
1063 }
1064 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001065 case CMD_REQUEST_CELL_INFO_UPDATE:
1066 request = (MainThreadRequest) msg.obj;
1067 request.phone.requestCellInfoUpdate(request.workSource,
1068 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1069 break;
1070 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1071 ar = (AsyncResult) msg.obj;
1072 request = (MainThreadRequest) ar.userObj;
1073 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1074 try {
1075 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001076 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Nathan Harolde82c4b82018-12-18 19:40:37 -08001077 cb.onError(TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1078 new android.os.ParcelableException(ar.exception));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001079 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001080 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Nathan Harolde82c4b82018-12-18 19:40:37 -08001081 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001082 } else {
1083 // use the result as returned
1084 cb.onCellInfo((List<CellInfo>) ar.result);
1085 }
1086 } catch (RemoteException re) {
1087 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1088 }
1089 break;
1090 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001091 request = (MainThreadRequest) msg.obj;
1092 WorkSource ws = (WorkSource) request.argument;
1093 Phone phone = getPhoneFromRequest(request);
1094 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1095 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001096 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001097 ar = (AsyncResult) msg.obj;
1098 request = (MainThreadRequest) ar.userObj;
1099 if (ar.exception == null) {
1100 request.result = ar.result;
1101 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001102 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001103 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1104 ? new CdmaCellLocation() : new GsmCellLocation();
1105 }
1106
1107 synchronized (request) {
1108 request.notifyAll();
1109 }
1110 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001111 case CMD_MODEM_REBOOT:
1112 request = (MainThreadRequest) msg.obj;
1113 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001114 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001115 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001116 case EVENT_CMD_MODEM_REBOOT_DONE:
1117 handleNullReturnEvent(msg, "rebootModem");
1118 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001119 case CMD_REQUEST_ENABLE_MODEM:
1120 request = (MainThreadRequest) msg.obj;
1121 boolean enable = (boolean) request.argument;
1122 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001123 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001124 PhoneConfigurationManager.getInstance()
1125 .enablePhone(request.phone, enable, onCompleted);
1126 break;
1127 case EVENT_ENABLE_MODEM_DONE:
1128 ar = (AsyncResult) msg.obj;
1129 request = (MainThreadRequest) ar.userObj;
1130 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001131 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001132 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001133 if ((boolean) request.result) {
1134 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1135 updateModemStateMetrics();
1136 } else {
1137 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1138 + ar.exception);
1139 }
1140 notifyRequester(request);
1141 break;
1142 case CMD_GET_MODEM_STATUS:
1143 request = (MainThreadRequest) msg.obj;
1144 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1145 PhoneConfigurationManager.getInstance()
1146 .getPhoneStatusFromModem(request.phone, onCompleted);
1147 break;
1148 case EVENT_GET_MODEM_STATUS_DONE:
1149 ar = (AsyncResult) msg.obj;
1150 request = (MainThreadRequest) ar.userObj;
1151 int id = request.phone.getPhoneId();
1152 if (ar.exception == null && ar.result != null) {
1153 request.result = ar.result;
1154 //update the cache as modem status has changed
1155 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1156 (boolean) request.result);
1157 } else {
1158 // Return true if modem status cannot be retrieved. For most cases,
1159 // modem status is on. And for older version modems, GET_MODEM_STATUS
1160 // and disable modem are not supported. Modem is always on.
1161 // TODO: this should be fixed in R to support a third
1162 // status UNKNOWN b/131631629
1163 request.result = true;
1164 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1165 + ar.exception);
1166 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001167 notifyRequester(request);
1168 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001169 default:
1170 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1171 break;
1172 }
1173 }
Jake Hambye994d462014-02-03 13:10:13 -08001174
Pengquan Menga1bb6272018-09-06 09:59:22 -07001175 private void notifyRequester(MainThreadRequest request) {
1176 synchronized (request) {
1177 request.notifyAll();
1178 }
1179 }
1180
Jake Hambye994d462014-02-03 13:10:13 -08001181 private void handleNullReturnEvent(Message msg, String command) {
1182 AsyncResult ar = (AsyncResult) msg.obj;
1183 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1184 if (ar.exception == null) {
1185 request.result = true;
1186 } else {
1187 request.result = false;
1188 if (ar.exception instanceof CommandException) {
1189 loge(command + ": CommandException: " + ar.exception);
1190 } else {
1191 loge(command + ": Unknown exception");
1192 }
1193 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001194 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001195 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001196 }
1197
1198 /**
1199 * Posts the specified command to be executed on the main thread,
1200 * waits for the request to complete, and returns the result.
1201 * @see #sendRequestAsync
1202 */
1203 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001204 return sendRequest(
1205 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001206 }
1207
1208 /**
1209 * Posts the specified command to be executed on the main thread,
1210 * waits for the request to complete, and returns the result.
1211 * @see #sendRequestAsync
1212 */
1213 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1214 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001215 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001216 }
1217
1218 /**
1219 * Posts the specified command to be executed on the main thread,
1220 * waits for the request to complete, and returns the result.
1221 * @see #sendRequestAsync
1222 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001223 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001224 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001225 }
1226
1227 /**
1228 * Posts the specified command to be executed on the main thread,
1229 * waits for the request to complete, and returns the result.
1230 * @see #sendRequestAsync
1231 */
Nathan Harold92bed182018-10-12 18:16:49 -07001232 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1233 return sendRequest(command, argument, subId, null, workSource);
1234 }
1235
1236 /**
1237 * Posts the specified command to be executed on the main thread,
1238 * waits for the request to complete, and returns the result.
1239 * @see #sendRequestAsync
1240 */
1241 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1242 return sendRequest(
1243 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1244 }
1245
1246 /**
1247 * Posts the specified command to be executed on the main thread,
1248 * waits for the request to complete, and returns the result.
1249 * @see #sendRequestAsync
1250 */
1251 private Object sendRequest(
1252 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001253 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1254 throw new RuntimeException("This method will deadlock if called from the main thread.");
1255 }
1256
Nathan Harold92bed182018-10-12 18:16:49 -07001257 MainThreadRequest request = null;
1258 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1259 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1260 } else if (phone != null) {
1261 request = new MainThreadRequest(argument, phone, workSource);
1262 } else {
1263 request = new MainThreadRequest(argument, subId, workSource);
1264 }
1265
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001266 Message msg = mMainThreadHandler.obtainMessage(command, request);
1267 msg.sendToTarget();
1268
1269 // Wait for the request to complete
1270 synchronized (request) {
1271 while (request.result == null) {
1272 try {
1273 request.wait();
1274 } catch (InterruptedException e) {
1275 // Do nothing, go back and wait until the request is complete
1276 }
1277 }
1278 }
1279 return request.result;
1280 }
1281
1282 /**
1283 * Asynchronous ("fire and forget") version of sendRequest():
1284 * Posts the specified command to be executed on the main thread, and
1285 * returns immediately.
1286 * @see #sendRequest
1287 */
1288 private void sendRequestAsync(int command) {
1289 mMainThreadHandler.sendEmptyMessage(command);
1290 }
1291
1292 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001293 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001294 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001295 */
1296 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001297 sendRequestAsync(command, argument, null, null);
1298 }
1299
1300 /**
1301 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1302 * @see {@link #sendRequest(int,Object)}
1303 */
1304 private void sendRequestAsync(
1305 int command, Object argument, Phone phone, WorkSource workSource) {
1306 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001307 Message msg = mMainThreadHandler.obtainMessage(command, request);
1308 msg.sendToTarget();
1309 }
1310
1311 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001312 * Initialize the singleton PhoneInterfaceManager instance.
1313 * This is only done once, at startup, from PhoneApp.onCreate().
1314 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001315 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001316 synchronized (PhoneInterfaceManager.class) {
1317 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001318 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001319 } else {
1320 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1321 }
1322 return sInstance;
1323 }
1324 }
1325
1326 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001327 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001328 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001329 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001330 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001331 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1332 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001333 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001334 mTelephonySharedPreferences =
1335 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001336 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001337 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001338
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001339 publish();
1340 }
1341
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001342 private Phone getDefaultPhone() {
1343 Phone thePhone = getPhone(getDefaultSubscription());
1344 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1345 }
1346
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001347 private void publish() {
1348 if (DBG) log("publish: " + this);
1349
1350 ServiceManager.addService("phone", this);
1351 }
1352
Stuart Scott584921c2015-01-15 17:10:34 -08001353 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001354 if (request.phone != null) {
1355 return request.phone;
1356 } else {
1357 return getPhoneFromSubId(request.subId);
1358 }
1359 }
1360
1361 private Phone getPhoneFromSubId(int subId) {
1362 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1363 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001364 }
1365
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001366 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1367 Phone phone = getPhoneFromRequest(request);
1368 return phone == null ? null :
1369 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1370 }
1371
Wink Saville36469e72014-06-11 15:17:00 -07001372 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001373 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001374 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001375 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001376
1377 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001378 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001379 }
1380
Wink Savilleb564aae2014-10-23 10:18:09 -07001381 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001382 if (DBG) log("dial: " + number);
1383 // No permission check needed here: This is just a wrapper around the
1384 // ACTION_DIAL intent, which is available to any app since it puts up
1385 // the UI before it does anything.
1386
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001387 final long identity = Binder.clearCallingIdentity();
1388 try {
1389 String url = createTelUrl(number);
1390 if (url == null) {
1391 return;
1392 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001393
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001394 // PENDING: should we just silently fail if phone is offhook or ringing?
1395 PhoneConstants.State state = mCM.getState(subId);
1396 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1397 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1398 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1399 mApp.startActivity(intent);
1400 }
1401 } finally {
1402 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001403 }
1404 }
1405
1406 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001407 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001408 }
1409
Wink Savilleb564aae2014-10-23 10:18:09 -07001410 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001411 if (DBG) log("call: " + number);
1412
1413 // This is just a wrapper around the ACTION_CALL intent, but we still
1414 // need to do a permission check since we're calling startActivity()
1415 // from the context of the phone app.
1416 enforceCallPermission();
1417
Jordan Liu1617b712019-07-10 15:06:26 -07001418 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001419 != AppOpsManager.MODE_ALLOWED) {
1420 return;
1421 }
1422
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001423 final long identity = Binder.clearCallingIdentity();
1424 try {
1425 String url = createTelUrl(number);
1426 if (url == null) {
1427 return;
1428 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001429
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001430 boolean isValid = false;
1431 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1432 if (slist != null) {
1433 for (SubscriptionInfo subInfoRecord : slist) {
1434 if (subInfoRecord.getSubscriptionId() == subId) {
1435 isValid = true;
1436 break;
1437 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001438 }
Wink Saville08874612014-08-31 19:19:58 -07001439 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001440 if (!isValid) {
1441 return;
1442 }
Wink Saville08874612014-08-31 19:19:58 -07001443
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001444 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1445 intent.putExtra(SUBSCRIPTION_KEY, subId);
1446 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1447 mApp.startActivity(intent);
1448 } finally {
1449 Binder.restoreCallingIdentity(identity);
1450 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001451 }
1452
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001453 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001454 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001455 }
1456
Wink Savilleb564aae2014-10-23 10:18:09 -07001457 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001458 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001459 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1460 }
1461
1462 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001463 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001464 }
1465
Wink Savilleb564aae2014-10-23 10:18:09 -07001466 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001467 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001468 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1469 }
1470
1471 /** {@hide} */
1472 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001473 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001474 }
1475
Wink Savilleb564aae2014-10-23 10:18:09 -07001476 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001477 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001478
1479 final long identity = Binder.clearCallingIdentity();
1480 try {
1481 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1482 checkSimPin.start();
1483 return checkSimPin.unlockSim(null, pin);
1484 } finally {
1485 Binder.restoreCallingIdentity(identity);
1486 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001487 }
1488
Wink Saville9de0f752013-10-22 19:04:03 -07001489 /** {@hide} */
1490 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001491 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001492 }
1493
Wink Savilleb564aae2014-10-23 10:18:09 -07001494 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001495 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001496
1497 final long identity = Binder.clearCallingIdentity();
1498 try {
1499 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1500 checkSimPuk.start();
1501 return checkSimPuk.unlockSim(puk, pin);
1502 } finally {
1503 Binder.restoreCallingIdentity(identity);
1504 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001505 }
1506
1507 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001508 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001509 * a synchronous one.
1510 */
1511 private static class UnlockSim extends Thread {
1512
1513 private final IccCard mSimCard;
1514
1515 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001516 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1517 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001518
1519 // For replies from SimCard interface
1520 private Handler mHandler;
1521
1522 // For async handler to identify request type
1523 private static final int SUPPLY_PIN_COMPLETE = 100;
1524
1525 public UnlockSim(IccCard simCard) {
1526 mSimCard = simCard;
1527 }
1528
1529 @Override
1530 public void run() {
1531 Looper.prepare();
1532 synchronized (UnlockSim.this) {
1533 mHandler = new Handler() {
1534 @Override
1535 public void handleMessage(Message msg) {
1536 AsyncResult ar = (AsyncResult) msg.obj;
1537 switch (msg.what) {
1538 case SUPPLY_PIN_COMPLETE:
1539 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1540 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001541 mRetryCount = msg.arg1;
1542 if (ar.exception != null) {
1543 if (ar.exception instanceof CommandException &&
1544 ((CommandException)(ar.exception)).getCommandError()
1545 == CommandException.Error.PASSWORD_INCORRECT) {
1546 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1547 } else {
1548 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1549 }
1550 } else {
1551 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1552 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001553 mDone = true;
1554 UnlockSim.this.notifyAll();
1555 }
1556 break;
1557 }
1558 }
1559 };
1560 UnlockSim.this.notifyAll();
1561 }
1562 Looper.loop();
1563 }
1564
1565 /*
1566 * Use PIN or PUK to unlock SIM card
1567 *
1568 * If PUK is null, unlock SIM card with PIN
1569 *
1570 * If PUK is not null, unlock SIM card with PUK and set PIN code
1571 */
Wink Saville9de0f752013-10-22 19:04:03 -07001572 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001573
1574 while (mHandler == null) {
1575 try {
1576 wait();
1577 } catch (InterruptedException e) {
1578 Thread.currentThread().interrupt();
1579 }
1580 }
1581 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1582
1583 if (puk == null) {
1584 mSimCard.supplyPin(pin, callback);
1585 } else {
1586 mSimCard.supplyPuk(puk, pin, callback);
1587 }
1588
1589 while (!mDone) {
1590 try {
1591 Log.d(LOG_TAG, "wait for done");
1592 wait();
1593 } catch (InterruptedException e) {
1594 // Restore the interrupted status
1595 Thread.currentThread().interrupt();
1596 }
1597 }
1598 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001599 int[] resultArray = new int[2];
1600 resultArray[0] = mResult;
1601 resultArray[1] = mRetryCount;
1602 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001603 }
1604 }
1605
1606 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001607 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001608
1609 }
1610
Wink Savilleb564aae2014-10-23 10:18:09 -07001611 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001612 // No permission check needed here: this call is harmless, and it's
1613 // needed for the ServiceState.requestStateUpdate() call (which is
1614 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001615 final long identity = Binder.clearCallingIdentity();
1616 try {
1617 final Phone phone = getPhone(subId);
1618 if (phone != null) {
1619 phone.updateServiceLocation();
1620 }
1621 } finally {
1622 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001623 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001624 }
1625
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001626 @Override
1627 public boolean isRadioOn(String callingPackage) {
1628 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001629 }
1630
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001631 @Override
1632 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001633 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001634 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001635 return false;
1636 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001637
1638 final long identity = Binder.clearCallingIdentity();
1639 try {
1640 return isRadioOnForSubscriber(subId);
1641 } finally {
1642 Binder.restoreCallingIdentity(identity);
1643 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001644 }
1645
1646 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001647 final long identity = Binder.clearCallingIdentity();
1648 try {
1649 final Phone phone = getPhone(subId);
1650 if (phone != null) {
1651 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1652 } else {
1653 return false;
1654 }
1655 } finally {
1656 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001657 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001658 }
1659
1660 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001661 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001662 }
Wink Saville36469e72014-06-11 15:17:00 -07001663
Wink Savilleb564aae2014-10-23 10:18:09 -07001664 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001665 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001666
1667 final long identity = Binder.clearCallingIdentity();
1668 try {
1669 final Phone phone = getPhone(subId);
1670 if (phone != null) {
1671 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1672 }
1673 } finally {
1674 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001675 }
Wink Saville36469e72014-06-11 15:17:00 -07001676 }
1677
1678 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001679 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001680 }
1681
Wink Savilleb564aae2014-10-23 10:18:09 -07001682 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001683 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001684
1685 final long identity = Binder.clearCallingIdentity();
1686 try {
1687 final Phone phone = getPhone(subId);
1688 if (phone == null) {
1689 return false;
1690 }
1691 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1692 toggleRadioOnOffForSubscriber(subId);
1693 }
1694 return true;
1695 } finally {
1696 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001697 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001698 }
Wink Saville36469e72014-06-11 15:17:00 -07001699
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001700 public boolean needMobileRadioShutdown() {
1701 /*
1702 * If any of the Radios are available, it will need to be
1703 * shutdown. So return true if any Radio is available.
1704 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001705 final long identity = Binder.clearCallingIdentity();
1706 try {
1707 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1708 Phone phone = PhoneFactory.getPhone(i);
1709 if (phone != null && phone.isRadioAvailable()) return true;
1710 }
1711 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1712 return false;
1713 } finally {
1714 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001715 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001716 }
1717
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001718 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001719 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001720 enforceModifyPermission();
1721
1722 final long identity = Binder.clearCallingIdentity();
1723 try {
1724 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1725 logv("Shutting down Phone " + i);
1726 shutdownRadioUsingPhoneId(i);
1727 }
1728 } finally {
1729 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001730 }
1731 }
1732
1733 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001734 Phone phone = PhoneFactory.getPhone(phoneId);
1735 if (phone != null && phone.isRadioAvailable()) {
1736 phone.shutdownRadio();
1737 }
1738 }
1739
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001740 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001741 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001742
1743 final long identity = Binder.clearCallingIdentity();
1744 try {
1745 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1746 if (defaultPhone != null) {
1747 defaultPhone.setRadioPower(turnOn);
1748 return true;
1749 } else {
1750 loge("There's no default phone.");
1751 return false;
1752 }
1753 } finally {
1754 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001755 }
Wink Saville36469e72014-06-11 15:17:00 -07001756 }
1757
Wink Savilleb564aae2014-10-23 10:18:09 -07001758 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001759 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001760
1761 final long identity = Binder.clearCallingIdentity();
1762 try {
1763 final Phone phone = getPhone(subId);
1764 if (phone != null) {
1765 phone.setRadioPower(turnOn);
1766 return true;
1767 } else {
1768 return false;
1769 }
1770 } finally {
1771 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001772 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001773 }
1774
Wink Saville36469e72014-06-11 15:17:00 -07001775 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001776 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001777 public boolean enableDataConnectivity() {
1778 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001779
1780 final long identity = Binder.clearCallingIdentity();
1781 try {
1782 int subId = mSubscriptionController.getDefaultDataSubId();
1783 final Phone phone = getPhone(subId);
1784 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001785 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001786 return true;
1787 } else {
1788 return false;
1789 }
1790 } finally {
1791 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001792 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001793 }
1794
Wink Saville36469e72014-06-11 15:17:00 -07001795 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001796 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001797 public boolean disableDataConnectivity() {
1798 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001799
1800 final long identity = Binder.clearCallingIdentity();
1801 try {
1802 int subId = mSubscriptionController.getDefaultDataSubId();
1803 final Phone phone = getPhone(subId);
1804 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001805 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001806 return true;
1807 } else {
1808 return false;
1809 }
1810 } finally {
1811 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001812 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001813 }
1814
Sanket Padawe356d7632015-06-22 14:03:32 -07001815 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001816 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001817 final long identity = Binder.clearCallingIdentity();
1818 try {
1819 final Phone phone = getPhone(subId);
1820 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001821 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001822 } else {
1823 return false;
1824 }
1825 } finally {
1826 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001827 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001828 }
1829
1830 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001831 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001832 }
1833
pkanwarae03a6b2016-11-06 20:37:09 -08001834 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001835 enforceCallPermission();
1836
1837 final long identity = Binder.clearCallingIdentity();
1838 try {
1839 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1840 return;
1841 }
1842 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1843 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1844 } finally {
1845 Binder.restoreCallingIdentity(identity);
1846 }
pkanwar32d516d2016-10-14 19:37:38 -07001847 };
1848
Wink Savilleb564aae2014-10-23 10:18:09 -07001849 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001850 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001851
1852 final long identity = Binder.clearCallingIdentity();
1853 try {
1854 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1855 return false;
1856 }
1857 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1858 } finally {
1859 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001860 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001861 }
1862
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001863 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001864 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001865 }
1866
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001867 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001868 final long identity = Binder.clearCallingIdentity();
1869 try {
1870 Phone phone = PhoneFactory.getPhone(slotIndex);
1871 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1872 PhoneConstantConversions.convertCallState(phone.getState());
1873 } finally {
1874 Binder.restoreCallingIdentity(identity);
1875 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001876 }
1877
Sanket Padawe356d7632015-06-22 14:03:32 -07001878 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001879 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001880 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
1881 }
1882
1883 @Override
1884 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001885 final long identity = Binder.clearCallingIdentity();
1886 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001887 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001888 if (phone != null) {
1889 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1890 } else {
1891 return PhoneConstantConversions.convertDataState(
1892 PhoneConstants.DataState.DISCONNECTED);
1893 }
1894 } finally {
1895 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001896 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001897 }
1898
Sanket Padawe356d7632015-06-22 14:03:32 -07001899 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001900 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001901 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
1902 }
1903
1904 @Override
1905 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001906 final long identity = Binder.clearCallingIdentity();
1907 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001908 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001909 if (phone != null) {
1910 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1911 } else {
1912 return TelephonyManager.DATA_ACTIVITY_NONE;
1913 }
1914 } finally {
1915 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001916 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001917 }
1918
1919 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001920 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001921 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001922 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08001923
1924 LocationAccessPolicy.LocationPermissionResult locationResult =
1925 LocationAccessPolicy.checkLocationPermission(mApp,
1926 new LocationAccessPolicy.LocationPermissionQuery.Builder()
1927 .setCallingPackage(callingPackage)
1928 .setCallingPid(Binder.getCallingPid())
1929 .setCallingUid(Binder.getCallingUid())
1930 .setMethod("getCellLocation")
1931 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
1932 .build());
1933 switch (locationResult) {
1934 case DENIED_HARD:
1935 throw new SecurityException("Not allowed to access cell location");
1936 case DENIED_SOFT:
1937 return new Bundle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001938 }
1939
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001940 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001941 final long identity = Binder.clearCallingIdentity();
1942 try {
1943 if (DBG_LOC) log("getCellLocation: is active user");
1944 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001945 int subId = mSubscriptionController.getDefaultDataSubId();
1946 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1947 cl.fillInNotifierBundle(data);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001948 return data;
1949 } finally {
1950 Binder.restoreCallingIdentity(identity);
1951 }
Svetoslav64fad262015-04-14 14:35:21 -07001952 }
1953
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001954 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001955 public String getNetworkCountryIsoForPhone(int phoneId) {
1956 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1957 // registered cell info, so return a NULL country instead.
1958 final long identity = Binder.clearCallingIdentity();
1959 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001960 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1961 // Get default phone in this case.
1962 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1963 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001964 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001965 // Todo: fix this when we can get the actual cellular network info when the device
1966 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001967 if (TelephonyManager.NETWORK_TYPE_IWLAN
1968 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1969 return "";
1970 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001971 Phone phone = PhoneFactory.getPhone(phoneId);
1972 if (phone != null) {
1973 ServiceStateTracker sst = phone.getServiceStateTracker();
sqian1c069d02019-07-31 20:23:45 -07001974 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001975 if (sst != null) {
1976 LocaleTracker lt = sst.getLocaleTracker();
1977 if (lt != null) {
sqian1c069d02019-07-31 20:23:45 -07001978 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
1979 return lt.getCurrentCountry();
1980 } else if (emergencyNumberTracker != null) {
1981 return emergencyNumberTracker.getEmergencyCountryIso();
1982 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001983 }
1984 }
1985 }
1986 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001987 } finally {
1988 Binder.restoreCallingIdentity(identity);
1989 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001990 }
1991
1992 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001993 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001994 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001995 }
1996
Sanket Padawe356d7632015-06-22 14:03:32 -07001997 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001998 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001999 mApp.enforceCallingOrSelfPermission(
2000 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002001
2002 final long identity = Binder.clearCallingIdentity();
2003 try {
2004 final Phone phone = getPhone(subId);
2005 if (phone != null) {
2006 phone.enableLocationUpdates();
2007 }
2008 } finally {
2009 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002010 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002011 }
2012
2013 @Override
2014 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002015 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002016 }
2017
Sanket Padawe356d7632015-06-22 14:03:32 -07002018 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002019 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002020 mApp.enforceCallingOrSelfPermission(
2021 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002022
2023 final long identity = Binder.clearCallingIdentity();
2024 try {
2025 final Phone phone = getPhone(subId);
2026 if (phone != null) {
2027 phone.disableLocationUpdates();
2028 }
2029 } finally {
2030 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002031 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002032 }
2033
Nathan Harold31d7ff32018-10-15 20:20:30 -07002034 /**
2035 * Returns the target SDK version number for a given package name.
2036 *
Nathan Haroldec184742019-07-10 17:04:16 -07002037 * This call MUST be invoked before clearing the calling UID.
2038 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002039 * @return target SDK if the package is found or INT_MAX.
2040 */
2041 private int getTargetSdk(String packageName) {
2042 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002043 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu54d20302019-07-30 15:12:06 -07002044 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002045 if (ai != null) return ai.targetSdkVersion;
2046 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002047 loge("Failed to get package info for pkg="
2048 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002049 }
2050 return Integer.MAX_VALUE;
2051 }
2052
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002053 @Override
2054 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07002055 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
2056 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002057 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2058 throw new SecurityException(
2059 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2060 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002061
Jordan Liu1617b712019-07-10 15:06:26 -07002062 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002063 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2064 return null;
2065 }
Svetoslav64fad262015-04-14 14:35:21 -07002066
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002067 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002068
Nathan Haroldf180aac2018-06-01 18:43:55 -07002069 List<CellInfo> info = getAllCellInfo(callingPackage);
2070 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002071
Nathan Haroldf180aac2018-06-01 18:43:55 -07002072 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2073 for (CellInfo ci : info) {
2074 if (ci instanceof CellInfoGsm) {
2075 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2076 } else if (ci instanceof CellInfoWcdma) {
2077 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2078 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002079 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002080 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002081 }
2082
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002083 private List<CellInfo> getCachedCellInfo() {
2084 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2085 for (Phone phone : PhoneFactory.getPhones()) {
2086 List<CellInfo> info = phone.getAllCellInfo();
2087 if (info != null) cellInfos.addAll(info);
2088 }
2089 return cellInfos;
2090 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002091
2092 @Override
Svetoslav64fad262015-04-14 14:35:21 -07002093 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002094 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002095 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002096
2097 LocationAccessPolicy.LocationPermissionResult locationResult =
2098 LocationAccessPolicy.checkLocationPermission(mApp,
2099 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2100 .setCallingPackage(callingPackage)
2101 .setCallingPid(Binder.getCallingPid())
2102 .setCallingUid(Binder.getCallingUid())
2103 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002104 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002105 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2106 .build());
2107 switch (locationResult) {
2108 case DENIED_HARD:
2109 throw new SecurityException("Not allowed to access cell info");
2110 case DENIED_SOFT:
2111 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002112 }
2113
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002114 final int targetSdk = getTargetSdk(callingPackage);
2115 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2116 return getCachedCellInfo();
2117 }
2118
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002119 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002120 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002121 final long identity = Binder.clearCallingIdentity();
2122 try {
2123 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2124 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002125 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002126 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002127 if (info != null) cellInfos.addAll(info);
2128 }
2129 return cellInfos;
2130 } finally {
2131 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002132 }
2133 }
2134
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002135 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002136 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2137 requestCellInfoUpdateInternal(
2138 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2139 }
2140
2141 @Override
2142 public void requestCellInfoUpdateWithWorkSource(
2143 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2144 enforceModifyPermission();
2145 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2146 }
2147
2148 private void requestCellInfoUpdateInternal(
2149 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002150 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002151 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002152
2153 LocationAccessPolicy.LocationPermissionResult locationResult =
2154 LocationAccessPolicy.checkLocationPermission(mApp,
2155 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2156 .setCallingPackage(callingPackage)
2157 .setCallingPid(Binder.getCallingPid())
2158 .setCallingUid(Binder.getCallingUid())
2159 .setMethod("requestCellInfoUpdate")
2160 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2161 .build());
2162 switch (locationResult) {
2163 case DENIED_HARD:
2164 throw new SecurityException("Not allowed to access cell info");
2165 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002166 try {
2167 cb.onCellInfo(new ArrayList<CellInfo>());
2168 } catch (RemoteException re) {
2169 // Drop without consequences
2170 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002171 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002172 }
2173
Nathan Harolda939a962019-05-09 10:13:47 -07002174
2175 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002176 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2177
2178 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2179 }
2180
2181 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002182 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002183 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002184 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002185
2186 final long identity = Binder.clearCallingIdentity();
2187 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002188 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002189 } finally {
2190 Binder.restoreCallingIdentity(identity);
2191 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002192 }
2193
Shishir Agrawala9f32182016-04-12 12:00:16 -07002194 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002195 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002196 Phone phone = PhoneFactory.getPhone(slotIndex);
2197 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002198 return null;
2199 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002200 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002201 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2202 callingPackage, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002203 return null;
2204 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002205
2206 final long identity = Binder.clearCallingIdentity();
2207 try {
2208 return phone.getImei();
2209 } finally {
2210 Binder.restoreCallingIdentity(identity);
2211 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002212 }
2213
2214 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002215 public String getTypeAllocationCodeForSlot(int slotIndex) {
2216 Phone phone = PhoneFactory.getPhone(slotIndex);
2217 String tac = null;
2218 if (phone != null) {
2219 String imei = phone.getImei();
2220 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2221 }
2222 return tac;
2223 }
2224
2225 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002226 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002227 Phone phone = PhoneFactory.getPhone(slotIndex);
2228 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002229 return null;
2230 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002231
Jeff Davidson913390f2018-02-23 17:11:49 -08002232 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002233 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2234 callingPackage, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002235 return null;
2236 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002237
2238 final long identity = Binder.clearCallingIdentity();
2239 try {
2240 return phone.getMeid();
2241 } finally {
2242 Binder.restoreCallingIdentity(identity);
2243 }
Jack Yu2af8d712017-03-15 17:14:14 -07002244 }
2245
2246 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002247 public String getManufacturerCodeForSlot(int slotIndex) {
2248 Phone phone = PhoneFactory.getPhone(slotIndex);
2249 String manufacturerCode = null;
2250 if (phone != null) {
2251 String meid = phone.getMeid();
2252 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2253 }
2254 return manufacturerCode;
2255 }
2256
2257 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002258 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002259 Phone phone = PhoneFactory.getPhone(slotIndex);
2260 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002261 return null;
2262 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002263 int subId = phone.getSubId();
2264 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2265 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2266 return null;
2267 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002268
2269 final long identity = Binder.clearCallingIdentity();
2270 try {
2271 return phone.getDeviceSvn();
2272 } finally {
2273 Binder.restoreCallingIdentity(identity);
2274 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002275 }
2276
fionaxu43304da2017-11-27 22:51:16 -08002277 @Override
2278 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002279 final long identity = Binder.clearCallingIdentity();
2280 try {
2281 final Phone phone = getPhone(subId);
2282 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2283 } finally {
2284 Binder.restoreCallingIdentity(identity);
2285 }
fionaxu43304da2017-11-27 22:51:16 -08002286 }
2287
2288 @Override
2289 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002290 final long identity = Binder.clearCallingIdentity();
2291 try {
2292 final Phone phone = getPhone(subId);
2293 return phone == null ? null : phone.getCarrierName();
2294 } finally {
2295 Binder.restoreCallingIdentity(identity);
2296 }
fionaxu43304da2017-11-27 22:51:16 -08002297 }
2298
calvinpanffe225e2018-11-01 19:43:06 +08002299 @Override
chen xu0026ca62019-03-06 15:28:50 -08002300 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002301 final long identity = Binder.clearCallingIdentity();
2302 try {
2303 final Phone phone = getPhone(subId);
2304 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002305 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002306 } finally {
2307 Binder.restoreCallingIdentity(identity);
2308 }
2309 }
2310
2311 @Override
chen xu0026ca62019-03-06 15:28:50 -08002312 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002313 final long identity = Binder.clearCallingIdentity();
2314 try {
2315 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002316 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002317 } finally {
2318 Binder.restoreCallingIdentity(identity);
2319 }
2320 }
2321
chen xu651eec72018-11-11 19:03:44 -08002322 @Override
chen xu864e11c2018-12-06 22:10:03 -08002323 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2324 if (!isSubscriptionMccMnc) {
2325 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2326 }
chen xu651eec72018-11-11 19:03:44 -08002327 final Phone phone = PhoneFactory.getPhone(slotIndex);
2328 if (phone == null) {
2329 return TelephonyManager.UNKNOWN_CARRIER_ID;
2330 }
2331 final long identity = Binder.clearCallingIdentity();
2332 try {
2333 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2334 } finally {
2335 Binder.restoreCallingIdentity(identity);
2336 }
2337 }
2338
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002339 //
2340 // Internal helper methods.
2341 //
2342
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002343 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002344 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2345 *
2346 * @throws SecurityException if the caller does not have the required permission
2347 */
2348 private void enforceModifyPermission() {
2349 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2350 }
2351
2352 /**
2353 * Make sure the caller has the CALL_PHONE permission.
2354 *
2355 * @throws SecurityException if the caller does not have the required permission
2356 */
2357 private void enforceCallPermission() {
2358 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2359 }
2360
Stuart Scott8eef64f2015-04-08 15:13:54 -07002361 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002362 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002363 "ConnectivityService");
2364 }
2365
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002366 private String createTelUrl(String number) {
2367 if (TextUtils.isEmpty(number)) {
2368 return null;
2369 }
2370
Jake Hambye994d462014-02-03 13:10:13 -08002371 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002372 }
2373
Ihab Awadf9e92732013-12-05 18:02:52 -08002374 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002375 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2376 }
2377
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002378 private static void logv(String msg) {
2379 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2380 }
2381
Ihab Awadf9e92732013-12-05 18:02:52 -08002382 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002383 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2384 }
2385
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002386 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002387 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002388 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002389 }
2390
Sanket Padawe356d7632015-06-22 14:03:32 -07002391 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002392 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002393 final long identity = Binder.clearCallingIdentity();
2394 try {
2395 final Phone phone = PhoneFactory.getPhone(slotIndex);
2396 if (phone == null) {
2397 return PhoneConstants.PHONE_TYPE_NONE;
2398 } else {
2399 return phone.getPhoneType();
2400 }
2401 } finally {
2402 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002403 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002404 }
2405
2406 /**
2407 * Returns the CDMA ERI icon index to display
2408 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002409 @Override
2410 public int getCdmaEriIconIndex(String callingPackage) {
2411 return getCdmaEriIconIndexForSubscriber(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 getCdmaEriIconIndexForSubscriber(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, "getCdmaEriIconIndexForSubscriber")) {
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.getCdmaEriIconIndex();
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 icon mode,
2436 * 0 - ON
2437 * 1 - FLASHING
2438 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002439 @Override
2440 public int getCdmaEriIconMode(String callingPackage) {
2441 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002442 }
2443
Sanket Padawe356d7632015-06-22 14:03:32 -07002444 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002445 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002446 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002447 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002448 return -1;
2449 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002450
2451 final long identity = Binder.clearCallingIdentity();
2452 try {
2453 final Phone phone = getPhone(subId);
2454 if (phone != null) {
2455 return phone.getCdmaEriIconMode();
2456 } else {
2457 return -1;
2458 }
2459 } finally {
2460 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002461 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002462 }
2463
2464 /**
2465 * Returns the CDMA ERI text,
2466 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002467 @Override
2468 public String getCdmaEriText(String callingPackage) {
2469 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002470 }
2471
Sanket Padawe356d7632015-06-22 14:03:32 -07002472 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002473 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002474 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002475 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002476 return null;
2477 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002478
2479 final long identity = Binder.clearCallingIdentity();
2480 try {
2481 final Phone phone = getPhone(subId);
2482 if (phone != null) {
2483 return phone.getCdmaEriText();
2484 } else {
2485 return null;
2486 }
2487 } finally {
2488 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002489 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002490 }
2491
2492 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002493 * Returns the CDMA MDN.
2494 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002495 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002496 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002497 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2498 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002499
2500 final long identity = Binder.clearCallingIdentity();
2501 try {
2502 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002503 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002504 return phone.getLine1Number();
2505 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002506 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002507 return null;
2508 }
2509 } finally {
2510 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002511 }
2512 }
2513
2514 /**
2515 * Returns the CDMA MIN.
2516 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002517 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002518 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002519 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2520 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002521
2522 final long identity = Binder.clearCallingIdentity();
2523 try {
2524 final Phone phone = getPhone(subId);
2525 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2526 return phone.getCdmaMin();
2527 } else {
2528 return null;
2529 }
2530 } finally {
2531 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002532 }
2533 }
2534
Hall Liud892bec2018-11-30 14:51:45 -08002535 @Override
2536 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2537 INumberVerificationCallback callback, String callingPackage) {
2538 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2539 != PERMISSION_GRANTED) {
2540 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2541 }
2542 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2543
2544 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2545 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2546 throw new SecurityException("Calling package must be configured in the device config");
2547 }
2548
2549 if (range == null) {
2550 throw new NullPointerException("Range must be non-null");
2551 }
2552
2553 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002554 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002555
2556 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2557 }
2558
Junda Liuca05d5d2014-08-14 22:36:34 -07002559 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002560 * Returns true if CDMA provisioning needs to run.
2561 */
2562 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002563 final long identity = Binder.clearCallingIdentity();
2564 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002565 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002566 } finally {
2567 Binder.restoreCallingIdentity(identity);
2568 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002569 }
2570
2571 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002572 * Sets the voice mail number of a given subId.
2573 */
2574 @Override
2575 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002576 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002577
2578 final long identity = Binder.clearCallingIdentity();
2579 try {
2580 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2581 new Pair<String, String>(alphaTag, number), new Integer(subId));
2582 return success;
2583 } finally {
2584 Binder.restoreCallingIdentity(identity);
2585 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002586 }
2587
Ta-wei Yen87c49842016-05-13 21:19:52 -07002588 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002589 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2590 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002591 String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002592 if (!TextUtils.equals(callingPackage, systemDialer)) {
2593 throw new SecurityException("caller must be system dialer");
2594 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002595
2596 final long identity = Binder.clearCallingIdentity();
2597 try {
2598 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2599 if (phoneAccountHandle == null) {
2600 return null;
2601 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002602 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002603 } finally {
2604 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002605 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002606 }
2607
2608 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002609 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002610 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002611 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002612 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002613 return null;
2614 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002615
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002616 final long identity = Binder.clearCallingIdentity();
2617 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002618 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002619 } finally {
2620 Binder.restoreCallingIdentity(identity);
2621 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002622 }
2623
2624 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002625 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2626 VisualVoicemailSmsFilterSettings settings) {
2627 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002628
2629 final long identity = Binder.clearCallingIdentity();
2630 try {
2631 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002632 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002633 } finally {
2634 Binder.restoreCallingIdentity(identity);
2635 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002636 }
2637
2638 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002639 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2640 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002641
2642 final long identity = Binder.clearCallingIdentity();
2643 try {
2644 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002645 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002646 } finally {
2647 Binder.restoreCallingIdentity(identity);
2648 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002649 }
2650
2651 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002652 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2653 String callingPackage, int subId) {
2654 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002655
2656 final long identity = Binder.clearCallingIdentity();
2657 try {
2658 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002659 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002660 } finally {
2661 Binder.restoreCallingIdentity(identity);
2662 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002663 }
2664
2665 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002666 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002667 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002668
2669 final long identity = Binder.clearCallingIdentity();
2670 try {
2671 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002672 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002673 } finally {
2674 Binder.restoreCallingIdentity(identity);
2675 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002676 }
2677
2678 @Override
2679 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2680 String number, int port, String text, PendingIntent sentIntent) {
2681 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002682 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002683 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07002684 SmsController smsController = PhoneFactory.getSmsController();
2685 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
2686 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002687 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07002688
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002689 /**
fionaxu0152e512016-11-14 13:36:14 -08002690 * Sets the voice activation state of a given subId.
2691 */
2692 @Override
2693 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002694 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2695 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002696
2697 final long identity = Binder.clearCallingIdentity();
2698 try {
2699 final Phone phone = getPhone(subId);
2700 if (phone != null) {
2701 phone.setVoiceActivationState(activationState);
2702 } else {
2703 loge("setVoiceActivationState fails with invalid subId: " + subId);
2704 }
2705 } finally {
2706 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002707 }
2708 }
2709
2710 /**
2711 * Sets the data activation state of a given subId.
2712 */
2713 @Override
2714 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002715 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2716 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002717
2718 final long identity = Binder.clearCallingIdentity();
2719 try {
2720 final Phone phone = getPhone(subId);
2721 if (phone != null) {
2722 phone.setDataActivationState(activationState);
2723 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09002724 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002725 }
2726 } finally {
2727 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002728 }
2729 }
2730
2731 /**
2732 * Returns the voice activation state of a given subId.
2733 */
2734 @Override
2735 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002736 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002737
fionaxu0152e512016-11-14 13:36:14 -08002738 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002739 final long identity = Binder.clearCallingIdentity();
2740 try {
2741 if (phone != null) {
2742 return phone.getVoiceActivationState();
2743 } else {
2744 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2745 }
2746 } finally {
2747 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002748 }
2749 }
2750
2751 /**
2752 * Returns the data activation state of a given subId.
2753 */
2754 @Override
2755 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002756 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002757
fionaxu0152e512016-11-14 13:36:14 -08002758 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002759 final long identity = Binder.clearCallingIdentity();
2760 try {
2761 if (phone != null) {
2762 return phone.getDataActivationState();
2763 } else {
2764 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2765 }
2766 } finally {
2767 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002768 }
2769 }
2770
2771 /**
Wink Saville36469e72014-06-11 15:17:00 -07002772 * Returns the unread count of voicemails for a subId
2773 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002774 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002775 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2776 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2777 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2778 return 0;
2779 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002780 final long identity = Binder.clearCallingIdentity();
2781 try {
2782 final Phone phone = getPhone(subId);
2783 if (phone != null) {
2784 return phone.getVoiceMessageCount();
2785 } else {
2786 return 0;
2787 }
2788 } finally {
2789 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002790 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002791 }
2792
2793 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002794 * returns true, if the device is in a state where both voice and data
2795 * are supported simultaneously. This can change based on location or network condition.
2796 */
2797 @Override
2798 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002799 final long identity = Binder.clearCallingIdentity();
2800 try {
2801 final Phone phone = getPhone(subId);
2802 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2803 } finally {
2804 Binder.restoreCallingIdentity(identity);
2805 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002806 }
2807
2808 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002809 * Send the dialer code if called from the current default dialer or the caller has
2810 * carrier privilege.
2811 * @param inputCode The dialer code to send
2812 */
2813 @Override
2814 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002815 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002816 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002817 String defaultDialer = TelecomManager.from(defaultPhone.getContext())
2818 .getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002819 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002820 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2821 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002822 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002823
2824 final long identity = Binder.clearCallingIdentity();
2825 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002826 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002827 } finally {
2828 Binder.restoreCallingIdentity(identity);
2829 }
fionaxu235cc5e2017-03-06 22:25:57 -08002830 }
2831
Pengquan Menga1bb6272018-09-06 09:59:22 -07002832 @Override
2833 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002834 if (!isActiveSubscription(subId)) {
2835 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2836 }
2837
Pengquan Menga1bb6272018-09-06 09:59:22 -07002838 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2839 }
2840
Brad Ebinger35c841c2018-10-01 10:40:55 -07002841 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002842 public boolean isInEmergencySmsMode() {
2843 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2844 final long identity = Binder.clearCallingIdentity();
2845 try {
2846 for (Phone phone : PhoneFactory.getPhones()) {
2847 if (phone.isInEmergencySmsMode()) {
2848 return true;
2849 }
2850 }
2851 } finally {
2852 Binder.restoreCallingIdentity(identity);
2853 }
2854 return false;
2855 }
2856
2857 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002858 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2859 throws RemoteException {
2860 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002861 final long token = Binder.clearCallingIdentity();
2862 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002863 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002864 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002865 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002866 } catch (ImsException e) {
2867 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002868 } 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);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002884 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002885 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);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002902 } catch (ImsException e) {
2903 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002904 } finally {
2905 Binder.restoreCallingIdentity(token);
2906 }
2907 }
2908
2909 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002910 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2911 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002912
2913 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2914 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2915 }
2916 Binder.withCleanCallingIdentity(() -> {
2917 try {
2918 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002919 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002920 .removeCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002921 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002922 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
2923 + "is inactive, ignoring unregister.");
2924 // If the subscription is no longer active, just return, since the callback
2925 // will already have been removed internally.
2926 }
2927 });
Brad Ebinger35c841c2018-10-01 10:40:55 -07002928 }
2929
2930 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002931 public boolean isCapable(int subId, int capability, int regTech) {
2932 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002933 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2934 final long token = Binder.clearCallingIdentity();
2935 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002936 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002937 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002938 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002939 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2940 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002941 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08002942 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
2943 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07002944 } finally {
2945 Binder.restoreCallingIdentity(token);
2946 }
2947 }
2948
2949 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002950 public boolean isAvailable(int subId, int capability, int regTech) {
2951 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002952 final long token = Binder.clearCallingIdentity();
2953 try {
2954 Phone phone = getPhone(subId);
2955 if (phone == null) return false;
2956 return phone.isImsCapabilityAvailable(capability, regTech);
2957 } finally {
2958 Binder.restoreCallingIdentity(token);
2959 }
2960 }
2961
2962 @Override
2963 public boolean isAdvancedCallingSettingEnabled(int subId) {
2964 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2965 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2966 final long token = Binder.clearCallingIdentity();
2967 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002968 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002969 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002970 } catch (ImsException e) {
2971 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002972 } finally {
2973 Binder.restoreCallingIdentity(token);
2974 }
2975 }
2976
2977 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08002978 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002979 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08002980 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002981 final long identity = Binder.clearCallingIdentity();
2982 try {
2983 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002984 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002985 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002986 } catch (ImsException e) {
2987 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002988 } finally {
2989 Binder.restoreCallingIdentity(identity);
2990 }
2991 }
2992
2993 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002994 public boolean isVtSettingEnabled(int subId) {
2995 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002996 final long identity = Binder.clearCallingIdentity();
2997 try {
2998 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002999 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3000 } catch (ImsException e) {
3001 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003002 } finally {
3003 Binder.restoreCallingIdentity(identity);
3004 }
3005 }
3006
3007 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003008 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003009 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003010 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003011 final long identity = Binder.clearCallingIdentity();
3012 try {
3013 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003014 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003015 } catch (ImsException e) {
3016 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003017 } finally {
3018 Binder.restoreCallingIdentity(identity);
3019 }
3020 }
3021
3022 @Override
3023 public boolean isVoWiFiSettingEnabled(int subId) {
3024 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3025 final long identity = Binder.clearCallingIdentity();
3026 try {
3027 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003028 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003029 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003030 } catch (ImsException e) {
3031 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003032 } finally {
3033 Binder.restoreCallingIdentity(identity);
3034 }
3035 }
3036
3037 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003038 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003039 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003040 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003041 final long identity = Binder.clearCallingIdentity();
3042 try {
3043 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003044 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003045 } catch (ImsException e) {
3046 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003047 } finally {
3048 Binder.restoreCallingIdentity(identity);
3049 }
3050 }
3051
3052 @Override
3053 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3054 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3055 final long identity = Binder.clearCallingIdentity();
3056 try {
3057 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003058 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003059 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003060 } catch (ImsException e) {
3061 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003062 } finally {
3063 Binder.restoreCallingIdentity(identity);
3064 }
3065 }
3066
3067 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003068 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003069 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003070 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003071 final long identity = Binder.clearCallingIdentity();
3072 try {
3073 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003074 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003075 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003076 } catch (ImsException e) {
3077 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003078 } finally {
3079 Binder.restoreCallingIdentity(identity);
3080 }
3081 }
3082
3083 @Override
3084 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3085 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3086 "setVoWiFiNonPersistent");
3087 final long identity = Binder.clearCallingIdentity();
3088 try {
3089 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003090 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003091 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003092 } catch (ImsException e) {
3093 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003094 } finally {
3095 Binder.restoreCallingIdentity(identity);
3096 }
3097 }
3098
3099 @Override
3100 public int getVoWiFiModeSetting(int subId) {
3101 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3102 final long identity = Binder.clearCallingIdentity();
3103 try {
3104 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003105 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003106 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003107 } catch (ImsException e) {
3108 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003109 } finally {
3110 Binder.restoreCallingIdentity(identity);
3111 }
3112 }
3113
3114 @Override
3115 public void setVoWiFiModeSetting(int subId, int mode) {
3116 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3117 "setVoWiFiModeSetting");
3118 final long identity = Binder.clearCallingIdentity();
3119 try {
3120 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003121 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003122 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003123 } catch (ImsException e) {
3124 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003125 } finally {
3126 Binder.restoreCallingIdentity(identity);
3127 }
3128 }
3129
3130 @Override
3131 public int getVoWiFiRoamingModeSetting(int subId) {
3132 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3133 final long identity = Binder.clearCallingIdentity();
3134 try {
3135 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003136 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003137 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003138 } catch (ImsException e) {
3139 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003140 } finally {
3141 Binder.restoreCallingIdentity(identity);
3142 }
3143 }
3144
3145 @Override
3146 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3147 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3148 "setVoWiFiRoamingModeSetting");
3149 final long identity = Binder.clearCallingIdentity();
3150 try {
3151 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003152 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003153 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003154 } catch (ImsException e) {
3155 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003156 } finally {
3157 Binder.restoreCallingIdentity(identity);
3158 }
3159 }
3160
3161 @Override
3162 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3163 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3164 "setRttCapabilityEnabled");
3165 final long identity = Binder.clearCallingIdentity();
3166 try {
3167 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003168 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3169 } catch (ImsException e) {
3170 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003171 } finally {
3172 Binder.restoreCallingIdentity(identity);
3173 }
3174 }
3175
3176 @Override
3177 public boolean isTtyOverVolteEnabled(int subId) {
3178 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3179 final long identity = Binder.clearCallingIdentity();
3180 try {
3181 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003182 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003183 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003184 } catch (ImsException e) {
3185 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003186 } finally {
3187 Binder.restoreCallingIdentity(identity);
3188 }
3189 }
3190
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003191 @Override
3192 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3193 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3194 final long identity = Binder.clearCallingIdentity();
3195 try {
3196 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003197 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003198 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003199 } catch (ImsException e) {
3200 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003201 } finally {
3202 Binder.restoreCallingIdentity(identity);
3203 }
3204 }
3205
3206 @Override
3207 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3208 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3209 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003210 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3211 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3212 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003213 try {
3214 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003215 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003216 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003217 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003218 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3219 + "is inactive, ignoring unregister.");
3220 // If the subscription is no longer active, just return, since the callback will already
3221 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003222 } finally {
3223 Binder.restoreCallingIdentity(identity);
3224 }
3225 }
3226
3227 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003228 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3229 boolean isProvisioned) {
3230 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3231 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3232 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3233 }
3234 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3235 "setProvisioningStatusForCapability");
3236 final long identity = Binder.clearCallingIdentity();
3237 try {
3238 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3239 Phone phone = getPhone(subId);
3240 if (phone == null) {
3241 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3242 + subId);
3243 return;
3244 }
3245 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3246 return;
3247 }
3248
3249 // this capability requires provisioning, route to the correct API.
3250 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3251 switch (capability) {
3252 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3253 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3254 ims.setVolteProvisioned(isProvisioned);
3255 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3256 ims.setWfcProvisioned(isProvisioned);
3257 }
3258 break;
3259 }
3260 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3261 // There is currently no difference in VT provisioning type.
3262 ims.setVtProvisioned(isProvisioned);
3263 break;
3264 }
3265 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3266 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3267 // change the capability of the feature instead if needed.
3268 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3269 == isProvisioned) {
3270 // No change in provisioning.
3271 return;
3272 }
3273 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3274 try {
3275 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003276 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003277 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3278 + ", Exception" + e.getMessage());
3279 }
3280 break;
3281 }
3282 default: {
3283 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3284 + capability + "', which does not require provisioning.");
3285 }
3286 }
3287
3288 } finally {
3289 Binder.restoreCallingIdentity(identity);
3290 }
3291 }
3292
3293 @Override
3294 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3295 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3296 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3297 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3298 }
3299 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3300 final long identity = Binder.clearCallingIdentity();
3301 try {
3302 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3303 Phone phone = getPhone(subId);
3304 if (phone == null) {
3305 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3306 + subId);
3307 // We will fail with "true" as the provisioning status because this is the default
3308 // if we do not require provisioning.
3309 return true;
3310 }
3311
3312 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3313 return true;
3314 }
3315
3316 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3317 switch (capability) {
3318 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3319 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3320 return ims.isVolteProvisionedOnDevice();
3321 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3322 return ims.isWfcProvisionedOnDevice();
3323 }
3324 // This should never happen, since we are checking tech above to make sure it
3325 // is either LTE or IWLAN.
3326 throw new IllegalArgumentException("Invalid radio technology for voice "
3327 + "capability.");
3328 }
3329 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3330 // There is currently no difference in VT provisioning type.
3331 return ims.isVtProvisionedOnDevice();
3332 }
3333 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3334 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3335 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3336 }
3337 default: {
3338 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3339 + capability + "', which does not require provisioning.");
3340 }
3341 }
3342
3343 } finally {
3344 Binder.restoreCallingIdentity(identity);
3345 }
3346 }
3347
3348 @Override
3349 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3350 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3351 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3352 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3353 }
3354 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3355 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3356 return (provisionedBits & capability) > 0;
3357 }
3358
3359 @Override
3360 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3361 boolean isProvisioned) {
3362 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3363 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3364 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3365 }
3366 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3367 "setProvisioningStatusForCapability");
3368 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3369 // If the current provisioning status for capability already matches isProvisioned,
3370 // do nothing.
3371 if (((provisionedBits & capability) > 0) == isProvisioned) {
3372 return;
3373 }
3374 if (isProvisioned) {
3375 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3376 } else {
3377 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3378 }
3379 }
3380
3381 /**
3382 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3383 * technology. The bitfield should mirror the bitfield defined by
3384 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3385 */
3386 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3387 String key = getMmTelProvisioningKey(subId, tech);
3388 // Default is no capabilities are provisioned.
3389 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3390 }
3391
3392 /**
3393 * Sets the MmTel capability provisioning bitfield (defined by
3394 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3395 * technology specified.
3396 *
3397 * Note: This is a synchronous command and should not be called on UI thread.
3398 */
3399 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3400 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3401 String key = getMmTelProvisioningKey(subId, tech);
3402 editor.putInt(key, newField);
3403 editor.commit();
3404 }
3405
3406 private static String getMmTelProvisioningKey(int subId, int tech) {
3407 // resulting key is provision_ims_mmtel_{subId}_{tech}
3408 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3409 }
3410
3411 /**
3412 * Query CarrierConfig to see if the specified capability requires provisioning for the
3413 * carrier associated with the subscription id.
3414 */
3415 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3416 int capability) {
3417 CarrierConfigManager configManager = new CarrierConfigManager(context);
3418 PersistableBundle c = configManager.getConfigForSubId(subId);
3419 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07003420 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003421 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3422 false);
3423 boolean requireVoiceVtProvisioning = c.getBoolean(
3424 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3425
3426 // First check to make sure that the capability requires provisioning.
3427 switch (capability) {
3428 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3429 // intentional fallthrough
3430 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3431 if (requireVoiceVtProvisioning) {
3432 // Voice and Video requires provisioning
3433 return true;
3434 }
3435 break;
3436 }
3437 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3438 if (requireUtProvisioning) {
3439 // UT requires provisioning
3440 return true;
3441 }
3442 break;
3443 }
3444 }
3445 return false;
3446 }
3447
3448 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003449 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003450 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3451 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3452 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003453 enforceReadPrivilegedPermission("getImsProvisioningInt");
3454 final long identity = Binder.clearCallingIdentity();
3455 try {
3456 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003457 int slotId = getSlotIndex(subId);
3458 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3459 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3460 + subId + "' for key:" + key);
3461 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3462 }
3463 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003464 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003465 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3466 + subId + "' for key:" + key);
3467 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003468 } finally {
3469 Binder.restoreCallingIdentity(identity);
3470 }
3471 }
3472
3473 @Override
3474 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003475 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3476 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3477 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003478 enforceReadPrivilegedPermission("getImsProvisioningString");
3479 final long identity = Binder.clearCallingIdentity();
3480 try {
3481 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003482 int slotId = getSlotIndex(subId);
3483 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3484 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3485 + subId + "' for key:" + key);
3486 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3487 }
3488 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003489 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003490 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3491 + subId + "' for key:" + key);
3492 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003493 } finally {
3494 Binder.restoreCallingIdentity(identity);
3495 }
3496 }
3497
3498 @Override
3499 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003500 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3501 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3502 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003503 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3504 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003505 final long identity = Binder.clearCallingIdentity();
3506 try {
3507 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003508 int slotId = getSlotIndex(subId);
3509 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3510 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3511 + subId + "' for key:" + key);
3512 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3513 }
3514 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003515 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003516 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3517 + "' for key:" + key);
3518 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003519 } finally {
3520 Binder.restoreCallingIdentity(identity);
3521 }
3522 }
3523
3524 @Override
3525 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003526 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3527 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3528 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003529 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3530 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003531 final long identity = Binder.clearCallingIdentity();
3532 try {
3533 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003534 int slotId = getSlotIndex(subId);
3535 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3536 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3537 + subId + "' for key:" + key);
3538 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3539 }
3540 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003541 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003542 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3543 + "' for key:" + key);
3544 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003545 } finally {
3546 Binder.restoreCallingIdentity(identity);
3547 }
3548 }
3549
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003550 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003551 int slotId = SubscriptionManager.getSlotIndex(subId);
3552 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003553 throw new ImsException("Invalid Subscription Id, subId=" + subId,
3554 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003555 }
3556 return slotId;
3557 }
3558
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003559 private int getSlotIndex(int subId) {
3560 int slotId = SubscriptionManager.getSlotIndex(subId);
3561 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3562 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3563 }
3564 return slotId;
3565 }
3566
Wink Saville36469e72014-06-11 15:17:00 -07003567 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07003568 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07003569 */
3570 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003571 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07003572 final int targetSdk = getTargetSdk(callingPackage);
3573 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
3574 return getDataNetworkTypeForSubscriber(subId, callingPackage);
3575 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07003576 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
3577 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003578 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3579 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003580
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003581 final long identity = Binder.clearCallingIdentity();
3582 try {
3583 final Phone phone = getPhone(subId);
3584 if (phone != null) {
3585 return phone.getServiceState().getDataNetworkType();
3586 } else {
3587 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3588 }
3589 } finally {
3590 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003591 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003592 }
3593
3594 /**
3595 * Returns the data network type
3596 */
3597 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003598 public int getDataNetworkType(String callingPackage) {
3599 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003600 }
3601
3602 /**
3603 * Returns the data network type for a subId
3604 */
3605 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003606 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003607 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003608 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003609 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3610 }
3611
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003612 final long identity = Binder.clearCallingIdentity();
3613 try {
3614 final Phone phone = getPhone(subId);
3615 if (phone != null) {
3616 return phone.getServiceState().getDataNetworkType();
3617 } else {
3618 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3619 }
3620 } finally {
3621 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003622 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003623 }
3624
3625 /**
Wink Saville36469e72014-06-11 15:17:00 -07003626 * Returns the Voice network type for a subId
3627 */
3628 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003629 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003630 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003631 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003632 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3633 }
3634
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003635 final long identity = Binder.clearCallingIdentity();
3636 try {
3637 final Phone phone = getPhone(subId);
3638 if (phone != null) {
3639 return phone.getServiceState().getVoiceNetworkType();
3640 } else {
3641 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3642 }
3643 } finally {
3644 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003645 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003646 }
3647
3648 /**
3649 * @return true if a ICC card is present
3650 */
3651 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003652 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003653 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3654 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003655 }
3656
3657 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003658 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003659 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003660 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003661 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003662 final long identity = Binder.clearCallingIdentity();
3663 try {
3664 final Phone phone = PhoneFactory.getPhone(slotIndex);
3665 if (phone != null) {
3666 return phone.getIccCard().hasIccCard();
3667 } else {
3668 return false;
3669 }
3670 } finally {
3671 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003672 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003673 }
3674
3675 /**
3676 * Return if the current radio is LTE on CDMA. This
3677 * is a tri-state return value as for a period of time
3678 * the mode may be unknown.
3679 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003680 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003681 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003682 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003683 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003684 @Override
3685 public int getLteOnCdmaMode(String callingPackage) {
3686 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003687 }
3688
Sanket Padawe356d7632015-06-22 14:03:32 -07003689 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003690 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003691 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003692 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003693 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3694 }
3695
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003696 final long identity = Binder.clearCallingIdentity();
3697 try {
3698 final Phone phone = getPhone(subId);
3699 if (phone == null) {
3700 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3701 } else {
3702 return phone.getLteOnCdmaMode();
3703 }
3704 } finally {
3705 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003706 }
Wink Saville36469e72014-06-11 15:17:00 -07003707 }
3708
Wink Saville36469e72014-06-11 15:17:00 -07003709 /**
3710 * {@hide}
3711 * Returns Default subId, 0 in the case of single standby.
3712 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003713 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003714 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003715 }
3716
Shishir Agrawala9f32182016-04-12 12:00:16 -07003717 private int getSlotForDefaultSubscription() {
3718 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3719 }
3720
Wink Savilleb564aae2014-10-23 10:18:09 -07003721 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003722 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003723 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003724
Pengquan Menge92a50d2018-09-21 15:54:48 -07003725 private boolean isActiveSubscription(int subId) {
3726 return mSubscriptionController.isActiveSubId(subId);
3727 }
3728
Ihab Awadf2177b72013-11-25 13:33:23 -08003729 /**
3730 * @see android.telephony.TelephonyManager.WifiCallingChoices
3731 */
3732 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003733 final long identity = Binder.clearCallingIdentity();
3734 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003735 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003736 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3737 getWhenToMakeWifiCallsDefaultPreference());
3738 } finally {
3739 Binder.restoreCallingIdentity(identity);
3740 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003741 }
3742
3743 /**
3744 * @see android.telephony.TelephonyManager.WifiCallingChoices
3745 */
3746 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003747 final long identity = Binder.clearCallingIdentity();
3748 try {
3749 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003750 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003751 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3752 } finally {
3753 Binder.restoreCallingIdentity(identity);
3754 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003755 }
3756
Sailesh Nepald1e68152013-12-12 19:08:02 -08003757 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003758 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003759 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003760 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003761
Jordan Liu4c733742019-02-28 12:03:40 -08003762 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
3763 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
3764 if (phoneId == -1) {
3765 throw new IllegalArgumentException("Given slot index: " + slotIndex
3766 + " does not correspond to an active phone");
3767 }
3768 return PhoneFactory.getPhone(phoneId);
3769 }
3770
Shishir Agrawal566b7612013-10-28 14:41:00 -07003771 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003772 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3773 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003774 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3775 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003776 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08003777 if (DBG) {
3778 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3779 }
3780 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
3781 p2);
3782 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003783
Jordan Liu4c733742019-02-28 12:03:40 -08003784
3785 @Override
3786 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
3787 int slotIndex, String callingPackage, String aid, int p2) {
3788 enforceModifyPermission();
3789 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3790 if (DBG) {
3791 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
3792 }
3793 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3794 callingPackage, aid, p2);
3795 }
3796
3797 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
3798 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003799 final long identity = Binder.clearCallingIdentity();
3800 try {
3801 if (TextUtils.equals(ISDR_AID, aid)) {
3802 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003803 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3804 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003805 if (bestComponent == null
3806 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3807 loge("The calling package is not allowed to access ISD-R.");
3808 throw new SecurityException(
3809 "The calling package is not allowed to access ISD-R.");
3810 }
Derek Tan740e1672017-06-27 14:56:27 -07003811 }
Derek Tan740e1672017-06-27 14:56:27 -07003812
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003813 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08003814 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
3815 null /* workSource */);
3816 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003817 return response;
3818 } finally {
3819 Binder.restoreCallingIdentity(identity);
3820 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003821 }
3822
3823 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003824 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003825 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3826 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08003827 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3828 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
3829 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003830
Jordan Liu4c733742019-02-28 12:03:40 -08003831 @Override
3832 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
3833 enforceModifyPermission();
3834 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
3835 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3836 channel);
3837 }
3838
3839 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003840 final long identity = Binder.clearCallingIdentity();
3841 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003842 if (channel < 0) {
3843 return false;
3844 }
Jordan Liu4c733742019-02-28 12:03:40 -08003845 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
3846 null /* workSource */);
3847 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003848 return success;
3849 } finally {
3850 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003851 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003852 }
3853
3854 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003855 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003856 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003857 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3858 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08003859 if (DBG) {
3860 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3861 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3862 + p3 + " data=" + data);
3863 }
3864 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
3865 command, p1, p2, p3, data);
3866 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003867
Jordan Liu4c733742019-02-28 12:03:40 -08003868 @Override
3869 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
3870 int command, int p1, int p2, int p3, String data) {
3871 enforceModifyPermission();
3872 if (DBG) {
3873 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
3874 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3875 + p3 + " data=" + data);
3876 }
3877 return iccTransmitApduLogicalChannelWithPermission(
3878 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
3879 data);
3880 }
3881
3882 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
3883 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003884 final long identity = Binder.clearCallingIdentity();
3885 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07003886 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003887 return "";
3888 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003889
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003890 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08003891 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
3892 null /* workSource */);
3893 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003894
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003895 // Append the returned status code to the end of the response payload.
3896 String s = Integer.toHexString(
3897 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3898 if (response.payload != null) {
3899 s = IccUtils.bytesToHexString(response.payload) + s;
3900 }
3901 return s;
3902 } finally {
3903 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003904 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003905 }
Jake Hambye994d462014-02-03 13:10:13 -08003906
Evan Charltonc66da362014-05-16 14:06:40 -07003907 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003908 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3909 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003910 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3911 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003912 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08003913 if (DBG) {
3914 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3915 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3916 }
3917 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
3918 cla, command, p1, p2, p3, data);
3919 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003920
Jordan Liu4c733742019-02-28 12:03:40 -08003921 @Override
3922 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
3923 int command, int p1, int p2, int p3, String data) {
3924 enforceModifyPermission();
3925 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3926 if (DBG) {
3927 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
3928 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
3929 + " data=" + data);
3930 }
3931
3932 return iccTransmitApduBasicChannelWithPermission(
3933 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
3934 p2, p3, data);
3935 }
3936
3937 // open APDU basic channel assuming the caller has sufficient permissions
3938 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
3939 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003940 final long identity = Binder.clearCallingIdentity();
3941 try {
3942 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3943 && TextUtils.equals(ISDR_AID, data)) {
3944 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003945 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3946 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003947 if (bestComponent == null
3948 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3949 loge("The calling package is not allowed to select ISD-R.");
3950 throw new SecurityException(
3951 "The calling package is not allowed to select ISD-R.");
3952 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003953 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003954
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003955 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08003956 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
3957 null /* workSource */);
3958 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003959
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003960 // Append the returned status code to the end of the response payload.
3961 String s = Integer.toHexString(
3962 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3963 if (response.payload != null) {
3964 s = IccUtils.bytesToHexString(response.payload) + s;
3965 }
3966 return s;
3967 } finally {
3968 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003969 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003970 }
3971
3972 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003973 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003974 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003975 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3976 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003977
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003978 final long identity = Binder.clearCallingIdentity();
3979 try {
3980 if (DBG) {
3981 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3982 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3983 }
3984
3985 IccIoResult response =
3986 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3987 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3988 subId);
3989
3990 if (DBG) {
3991 log("Exchange SIM_IO [R]" + response);
3992 }
3993
3994 byte[] result = null;
3995 int length = 2;
3996 if (response.payload != null) {
3997 length = 2 + response.payload.length;
3998 result = new byte[length];
3999 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4000 } else {
4001 result = new byte[length];
4002 }
4003
4004 result[length - 1] = (byte) response.sw2;
4005 result[length - 2] = (byte) response.sw1;
4006 return result;
4007 } finally {
4008 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004009 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004010 }
4011
Nathan Haroldb3014052017-01-25 15:57:32 -08004012 /**
4013 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4014 * on a particular subscription
4015 */
sqianb6e41952018-03-12 14:54:01 -07004016 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
4017 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4018 mApp, subId, callingPackage, "getForbiddenPlmns")) {
4019 return null;
4020 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004021
4022 final long identity = Binder.clearCallingIdentity();
4023 try {
4024 if (appType != TelephonyManager.APPTYPE_USIM
4025 && appType != TelephonyManager.APPTYPE_SIM) {
4026 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4027 return null;
4028 }
4029 Object response = sendRequest(
4030 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4031 if (response instanceof String[]) {
4032 return (String[]) response;
4033 }
4034 // Response is an Exception of some kind,
4035 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004036 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004037 } finally {
4038 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004039 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004040 }
4041
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004042 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004043 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004044 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4045 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004046
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004047 final long identity = Binder.clearCallingIdentity();
4048 try {
4049 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4050 if (response.payload == null) {
4051 return "";
4052 }
Evan Charltonc66da362014-05-16 14:06:40 -07004053
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004054 // Append the returned status code to the end of the response payload.
4055 String s = Integer.toHexString(
4056 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4057 s = IccUtils.bytesToHexString(response.payload) + s;
4058 return s;
4059 } finally {
4060 Binder.restoreCallingIdentity(identity);
4061 }
Evan Charltonc66da362014-05-16 14:06:40 -07004062 }
4063
Jake Hambye994d462014-02-03 13:10:13 -08004064 /**
4065 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4066 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4067 *
4068 * @param itemID the ID of the item to read
4069 * @return the NV item as a String, or null on error.
4070 */
4071 @Override
4072 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004073 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004074 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4075 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004076
4077 final long identity = Binder.clearCallingIdentity();
4078 try {
4079 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004080 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004081 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4082 return value;
4083 } finally {
4084 Binder.restoreCallingIdentity(identity);
4085 }
Jake Hambye994d462014-02-03 13:10:13 -08004086 }
4087
4088 /**
4089 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4090 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4091 *
4092 * @param itemID the ID of the item to read
4093 * @param itemValue the value to write, as a String
4094 * @return true on success; false on any failure
4095 */
4096 @Override
4097 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004098 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004099 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4100 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004101
4102 final long identity = Binder.clearCallingIdentity();
4103 try {
4104 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4105 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004106 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004107 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4108 return success;
4109 } finally {
4110 Binder.restoreCallingIdentity(identity);
4111 }
Jake Hambye994d462014-02-03 13:10:13 -08004112 }
4113
4114 /**
4115 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4116 * Used for device configuration by some CDMA operators.
4117 *
4118 * @param preferredRoamingList byte array containing the new PRL
4119 * @return true on success; false on any failure
4120 */
4121 @Override
4122 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004123 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4124 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004125
4126 final long identity = Binder.clearCallingIdentity();
4127 try {
4128 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4129 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4130 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4131 return success;
4132 } finally {
4133 Binder.restoreCallingIdentity(identity);
4134 }
Jake Hambye994d462014-02-03 13:10:13 -08004135 }
4136
4137 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004138 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004139 * Used for device configuration by some CDMA operators.
4140 *
chen xu6dac5ab2018-10-26 17:39:23 -07004141 * @param slotIndex - device slot.
4142 *
Jake Hambye994d462014-02-03 13:10:13 -08004143 * @return true on success; false on any failure
4144 */
4145 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004146 public boolean resetModemConfig(int slotIndex) {
4147 Phone phone = PhoneFactory.getPhone(slotIndex);
4148 if (phone != null) {
4149 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4150 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004151
chen xu6dac5ab2018-10-26 17:39:23 -07004152 final long identity = Binder.clearCallingIdentity();
4153 try {
4154 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4155 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4156 return success;
4157 } finally {
4158 Binder.restoreCallingIdentity(identity);
4159 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004160 }
chen xu6dac5ab2018-10-26 17:39:23 -07004161 return false;
4162 }
4163
4164 /**
4165 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4166 *
4167 * @param slotIndex - device slot.
4168 *
4169 * @return true on success; false on any failure
4170 */
4171 @Override
4172 public boolean rebootModem(int slotIndex) {
4173 Phone phone = PhoneFactory.getPhone(slotIndex);
4174 if (phone != null) {
4175 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4176 mApp, phone.getSubId(), "rebootModem");
4177
4178 final long identity = Binder.clearCallingIdentity();
4179 try {
4180 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4181 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4182 return success;
4183 } finally {
4184 Binder.restoreCallingIdentity(identity);
4185 }
4186 }
4187 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004188 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004189
Svet Ganovb320e182015-04-16 12:30:10 -07004190 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004191 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004192 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004193 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004194 return new String[0];
4195 }
4196
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004197 final long identity = Binder.clearCallingIdentity();
4198 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004199 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004200 } finally {
4201 Binder.restoreCallingIdentity(identity);
4202 }
Wink Saville36469e72014-06-11 15:17:00 -07004203 }
4204
Brad Ebinger51f743a2017-01-23 13:50:20 -08004205 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004206 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4207 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004208 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004209 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004210 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004211
4212 final long identity = Binder.clearCallingIdentity();
4213 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004214 ImsResolver resolver = PhoneFactory.getImsResolver();
4215 if (resolver == null) {
4216 // may happen if the device does not support IMS.
4217 return;
4218 }
4219 resolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004220 } finally {
4221 Binder.restoreCallingIdentity(identity);
4222 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004223 }
4224
4225 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004226 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4227 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004228 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004229 public void disableIms(int slotId) {
4230 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004231
4232 final long identity = Binder.clearCallingIdentity();
4233 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004234 ImsResolver resolver = PhoneFactory.getImsResolver();
4235 if (resolver == null) {
4236 // may happen if the device does not support IMS.
4237 return;
4238 }
4239 resolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004240 } finally {
4241 Binder.restoreCallingIdentity(identity);
4242 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004243 }
4244
4245 /**
4246 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4247 * feature or {@link null} if the service is not available. If the feature is available, the
4248 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4249 */
4250 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004251 IImsServiceFeatureCallback callback) {
4252 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004253
4254 final long identity = Binder.clearCallingIdentity();
4255 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004256 ImsResolver resolver = PhoneFactory.getImsResolver();
4257 if (resolver == null) {
4258 // may happen if the device does not support IMS.
4259 return null;
4260 }
4261 return resolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004262 } finally {
4263 Binder.restoreCallingIdentity(identity);
4264 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004265 }
4266
4267 /**
4268 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4269 * feature during emergency calling or {@link null} if the service is not available. If the
4270 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4271 * listener for feature updates.
4272 */
4273 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4274 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004275
4276 final long identity = Binder.clearCallingIdentity();
4277 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004278 ImsResolver resolver = PhoneFactory.getImsResolver();
4279 if (resolver == null) {
4280 // may happen if the device does not support IMS.
4281 return null;
4282 }
4283 return resolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004284 } finally {
4285 Binder.restoreCallingIdentity(identity);
4286 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004287 }
4288
Brad Ebinger5f64b052017-12-14 14:26:15 -08004289 /**
4290 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004291 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004292 */
4293 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4294 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004295
4296 final long identity = Binder.clearCallingIdentity();
4297 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004298 ImsResolver resolver = PhoneFactory.getImsResolver();
4299 if (resolver == null) {
4300 // may happen if the device does not support IMS.
4301 return null;
4302 }
4303 return resolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004304 } finally {
4305 Binder.restoreCallingIdentity(identity);
4306 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004307 }
4308
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004309 /**
4310 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004311 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004312 */
4313 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4314 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004315
4316 final long identity = Binder.clearCallingIdentity();
4317 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004318 ImsResolver resolver = PhoneFactory.getImsResolver();
4319 if (resolver == null) {
4320 // may happen if the device does not support IMS.
4321 return null;
4322 }
4323 return resolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004324 } finally {
4325 Binder.restoreCallingIdentity(identity);
4326 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004327 }
4328
Brad Ebinger884c07b2018-02-15 16:17:40 -08004329 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004330 * Sets the ImsService Package Name that Telephony will bind to.
4331 *
4332 * @param slotId the slot ID that the ImsService should bind for.
4333 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4334 * ImsService is the device default ImsService.
4335 * @param packageName The package name of the application that contains the ImsService to bind
4336 * to.
4337 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4338 * @hide
4339 */
4340 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004341 int[] subIds = SubscriptionManager.getSubId(slotId);
4342 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4343 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4344 "setImsService");
4345
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004346 final long identity = Binder.clearCallingIdentity();
4347 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004348 ImsResolver resolver = PhoneFactory.getImsResolver();
4349 if (resolver == null) {
4350 // may happen if the device does not support IMS.
4351 return false;
4352 }
4353 return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService,
4354 packageName);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004355 } finally {
4356 Binder.restoreCallingIdentity(identity);
4357 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004358 }
4359
4360 /**
4361 * Return the ImsService configuration.
4362 *
4363 * @param slotId The slot that the ImsService is associated with.
4364 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4365 * the device default.
4366 * @return the package name of the ImsService configuration.
4367 */
4368 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004369 int[] subIds = SubscriptionManager.getSubId(slotId);
4370 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4371 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4372 "getImsService");
4373
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004374 final long identity = Binder.clearCallingIdentity();
4375 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004376 ImsResolver resolver = PhoneFactory.getImsResolver();
4377 if (resolver == null) {
4378 // may happen if the device does not support IMS.
4379 return "";
4380 }
4381 return resolver.getImsServiceConfiguration(slotId, isCarrierImsService);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004382 } finally {
4383 Binder.restoreCallingIdentity(identity);
4384 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004385 }
4386
Wink Saville36469e72014-06-11 15:17:00 -07004387 public void setImsRegistrationState(boolean registered) {
4388 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004389
4390 final long identity = Binder.clearCallingIdentity();
4391 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004392 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004393 } finally {
4394 Binder.restoreCallingIdentity(identity);
4395 }
Wink Saville36469e72014-06-11 15:17:00 -07004396 }
4397
4398 /**
Stuart Scott54788802015-03-30 13:18:01 -07004399 * Set the network selection mode to automatic.
4400 *
4401 */
4402 @Override
4403 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004404 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4405 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004406
Pengquan Menge92a50d2018-09-21 15:54:48 -07004407 if (!isActiveSubscription(subId)) {
4408 return;
4409 }
4410
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004411 final long identity = Binder.clearCallingIdentity();
4412 try {
4413 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4414 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4415 } finally {
4416 Binder.restoreCallingIdentity(identity);
4417 }
Stuart Scott54788802015-03-30 13:18:01 -07004418 }
4419
Pengquan Mengea84e042018-09-20 14:57:26 -07004420 /**
4421 * Ask the radio to connect to the input network and change selection mode to manual.
4422 *
4423 * @param subId the id of the subscription.
4424 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4425 * the operator to attach to.
4426 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4427 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4428 * normal network selection next time.
4429 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004430 */
4431 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004432 public boolean setNetworkSelectionModeManual(
4433 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004434 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4435 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004436
4437 if (!isActiveSubscription(subId)) {
4438 return false;
4439 }
4440
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004441 final long identity = Binder.clearCallingIdentity();
4442 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004443 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004444 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004445 if (DBG) {
4446 log("setNetworkSelectionModeManual: subId: " + subId
4447 + " operator: " + operatorInfo);
4448 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004449 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4450 } finally {
4451 Binder.restoreCallingIdentity(identity);
4452 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004453 }
4454
4455 /**
4456 * Scans for available networks.
4457 */
4458 @Override
Hall Liuf19c44f2018-11-27 14:38:17 -08004459 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004460 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4461 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004462 LocationAccessPolicy.LocationPermissionResult locationResult =
4463 LocationAccessPolicy.checkLocationPermission(mApp,
4464 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4465 .setCallingPackage(callingPackage)
4466 .setCallingPid(Binder.getCallingPid())
4467 .setCallingUid(Binder.getCallingUid())
4468 .setMethod("getCellNetworkScanResults")
4469 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4470 .build());
4471 switch (locationResult) {
4472 case DENIED_HARD:
4473 throw new SecurityException("Not allowed to access scan results -- location");
4474 case DENIED_SOFT:
4475 return null;
4476 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004477
Pengquan Menga1bb6272018-09-06 09:59:22 -07004478 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004479 try {
4480 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004481 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004482 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004483 } finally {
4484 Binder.restoreCallingIdentity(identity);
4485 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004486 }
4487
4488 /**
yinxub1bed742017-04-17 11:45:04 -07004489 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004490 *
yinxub1bed742017-04-17 11:45:04 -07004491 * @param subId id of the subscription
4492 * @param request contains the radio access networks with bands/channels to scan
4493 * @param messenger callback messenger for scan results or errors
4494 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004495 * @return the id of the requested scan which can be used to stop the scan.
4496 */
4497 @Override
4498 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Hall Liuf19c44f2018-11-27 14:38:17 -08004499 IBinder binder, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004500 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4501 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004502 LocationAccessPolicy.LocationPermissionResult locationResult =
4503 LocationAccessPolicy.checkLocationPermission(mApp,
4504 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4505 .setCallingPackage(callingPackage)
4506 .setCallingPid(Binder.getCallingPid())
4507 .setCallingUid(Binder.getCallingUid())
4508 .setMethod("requestNetworkScan")
4509 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4510 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004511 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07004512 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08004513 if (e != null) {
4514 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4515 throw e;
4516 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07004517 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004518 return TelephonyScanManager.INVALID_SCAN_ID;
4519 }
4520 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004521 }
Hall Liu912dfd32019-04-25 14:02:26 -07004522 int callingUid = Binder.getCallingUid();
4523 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07004524 final long identity = Binder.clearCallingIdentity();
4525 try {
4526 return mNetworkScanRequestTracker.startNetworkScan(
4527 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07004528 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07004529 } finally {
4530 Binder.restoreCallingIdentity(identity);
4531 }
yinxu504e1392017-04-12 16:03:22 -07004532 }
4533
Hall Liub2ac8ef2019-02-28 15:56:23 -08004534 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07004535 NetworkScanRequest request, int subId) {
4536 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
4537 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
4538 boolean hasNetworkScanPermission =
4539 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4540 == PERMISSION_GRANTED;
4541
4542 if (!hasCarrierPriv && !hasNetworkScanPermission) {
4543 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
4544 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08004545 }
4546
4547 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4548 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004549 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4550 return new SecurityException("Specific channels must not be"
4551 + " scanned without location access.");
4552 }
4553 }
4554 }
4555
Hall Liub2ac8ef2019-02-28 15:56:23 -08004556 return null;
4557 }
4558
yinxu504e1392017-04-12 16:03:22 -07004559 /**
4560 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004561 *
4562 * @param subId id of the subscription
4563 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004564 */
4565 @Override
4566 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004567 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4568 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004569
Hall Liu912dfd32019-04-25 14:02:26 -07004570 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004571 final long identity = Binder.clearCallingIdentity();
4572 try {
Hall Liu912dfd32019-04-25 14:02:26 -07004573 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004574 } finally {
4575 Binder.restoreCallingIdentity(identity);
4576 }
yinxu504e1392017-04-12 16:03:22 -07004577 }
4578
4579 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004580 * Get the calculated preferred network type.
4581 * Used for debugging incorrect network type.
4582 *
4583 * @return the preferred network type, defined in RILConstants.java.
4584 */
4585 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004586 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004587 final Phone defaultPhone = getDefaultPhone();
4588 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4589 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004590 return RILConstants.PREFERRED_NETWORK_MODE;
4591 }
4592
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004593 final long identity = Binder.clearCallingIdentity();
4594 try {
4595 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004596 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004597 } finally {
4598 Binder.restoreCallingIdentity(identity);
4599 }
Junda Liu84d15a22014-07-02 11:21:04 -07004600 }
4601
4602 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004603 * Get the preferred network type.
4604 * Used for device configuration by some CDMA operators.
4605 *
4606 * @return the preferred network type, defined in RILConstants.java.
4607 */
4608 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004609 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08004610 TelephonyPermissions
4611 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4612 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004613
4614 final long identity = Binder.clearCallingIdentity();
4615 try {
4616 if (DBG) log("getPreferredNetworkType");
4617 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4618 int networkType = (result != null ? result[0] : -1);
4619 if (DBG) log("getPreferredNetworkType: " + networkType);
4620 return networkType;
4621 } finally {
4622 Binder.restoreCallingIdentity(identity);
4623 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004624 }
4625
4626 /**
4627 * Set the preferred network type.
4628 * Used for device configuration by some CDMA operators.
4629 *
4630 * @param networkType the preferred network type, defined in RILConstants.java.
4631 * @return true on success; false on any failure.
4632 */
4633 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004634 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004635 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4636 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004637
4638 final long identity = Binder.clearCallingIdentity();
4639 try {
4640 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4641 Boolean success = (Boolean) sendRequest(
4642 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4643 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4644 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004645 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004646 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4647 }
4648 return success;
4649 } finally {
4650 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004651 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004652 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004653
4654 /**
Miaoa84611c2019-03-15 09:21:10 +08004655 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004656 *
Miaoa84611c2019-03-15 09:21:10 +08004657 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004658 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004659 * @hide
4660 */
4661 @Override
Miaoa84611c2019-03-15 09:21:10 +08004662 public boolean getTetherApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004663 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004664 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08004665 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004666 try {
Miaoa84611c2019-03-15 09:21:10 +08004667 if (phone != null) {
4668 return phone.hasMatchedTetherApnSetting();
4669 } else {
4670 return false;
4671 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004672 } finally {
4673 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004674 }
Junda Liu475951f2014-11-07 16:45:03 -08004675 }
4676
4677 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004678 * Set mobile data enabled
4679 * Used by the user through settings etc to turn on/off mobile data
4680 *
4681 * @param enable {@code true} turn turn data on, else {@code false}
4682 */
4683 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004684 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004685 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4686 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004687
4688 final long identity = Binder.clearCallingIdentity();
4689 try {
4690 int phoneId = mSubscriptionController.getPhoneId(subId);
4691 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4692 Phone phone = PhoneFactory.getPhone(phoneId);
4693 if (phone != null) {
4694 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08004695 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004696 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004697 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004698 }
4699 } finally {
4700 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004701 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004702 }
4703
4704 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004705 * Get the user enabled state of Mobile Data.
4706 *
4707 * TODO: remove and use isUserDataEnabled.
4708 * This can't be removed now because some vendor codes
4709 * calls through ITelephony directly while they should
4710 * use TelephonyManager.
4711 *
4712 * @return true on enabled
4713 */
4714 @Override
4715 public boolean getDataEnabled(int subId) {
4716 return isUserDataEnabled(subId);
4717 }
4718
4719 /**
4720 * Get whether mobile data is enabled per user setting.
4721 *
4722 * There are other factors deciding whether mobile data is actually enabled, but they are
4723 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004724 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004725 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004726 *
4727 * @return {@code true} if data is enabled else {@code false}
4728 */
4729 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004730 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004731 try {
4732 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4733 null);
4734 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004735 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4736 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004737 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004738
4739 final long identity = Binder.clearCallingIdentity();
4740 try {
4741 int phoneId = mSubscriptionController.getPhoneId(subId);
4742 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4743 Phone phone = PhoneFactory.getPhone(phoneId);
4744 if (phone != null) {
4745 boolean retVal = phone.isUserDataEnabled();
4746 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4747 return retVal;
4748 } else {
4749 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4750 return false;
4751 }
4752 } finally {
4753 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004754 }
4755 }
4756
4757 /**
4758 * Get whether mobile data is enabled.
4759 *
4760 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4761 * whether mobile data is actually enabled.
4762 *
4763 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4764 *
4765 * @return {@code true} if data is enabled else {@code false}
4766 */
4767 @Override
4768 public boolean isDataEnabled(int subId) {
4769 try {
4770 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4771 null);
4772 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004773 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4774 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004775 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004776
4777 final long identity = Binder.clearCallingIdentity();
4778 try {
4779 int phoneId = mSubscriptionController.getPhoneId(subId);
4780 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4781 Phone phone = PhoneFactory.getPhone(phoneId);
4782 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08004783 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004784 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4785 return retVal;
4786 } else {
4787 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4788 return false;
4789 }
4790 } finally {
4791 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004792 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004793 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004794
4795 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004796 public int getCarrierPrivilegeStatus(int subId) {
4797 final Phone phone = getPhone(subId);
4798 if (phone == null) {
4799 loge("getCarrierPrivilegeStatus: Invalid subId");
4800 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4801 }
4802 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004803 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004804 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004805 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4806 }
4807 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004808 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004809 }
Junda Liu29340342014-07-10 15:23:27 -07004810
4811 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004812 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4813 final Phone phone = getPhone(subId);
4814 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09004815 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08004816 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4817 }
4818 UiccProfile profile =
4819 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4820 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09004821 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08004822 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4823 }
4824 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4825 }
4826
4827 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07004828 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
4829 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08004830 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07004831 }
4832
4833 int phoneId = SubscriptionManager.getPhoneId(subId);
4834 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004835 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07004836 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004837 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4838 }
chen xuf7e9fe82019-05-09 19:31:02 -07004839
4840 return card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004841 }
4842
4843 @Override
4844 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004845 if (TextUtils.isEmpty(pkgName))
4846 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004847 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4848 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4849 UiccCard card = UiccController.getInstance().getUiccCard(i);
4850 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004851 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004852 continue;
4853 }
4854
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004855 result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004856 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4857 break;
4858 }
4859 }
4860
4861 return result;
Junda Liu29340342014-07-10 15:23:27 -07004862 }
Derek Tan89e89d42014-07-08 17:00:10 -07004863
4864 @Override
Junda Liue64de782015-04-16 17:19:16 -07004865 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4866 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4867 loge("phoneId " + phoneId + " is not valid.");
4868 return null;
4869 }
4870 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004871 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09004872 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004873 return null ;
4874 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004875 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004876 }
4877
Amith Yamasani6e118872016-02-19 12:53:51 -08004878 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07004879 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004880 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08004881 List<String> privilegedPackages = new ArrayList<>();
4882 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07004883 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
4884 // has UICC in that slot.
4885 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08004886 if (card.hasCarrierPrivilegeRules()) {
4887 if (packages == null) {
4888 // Only check packages in user 0 for now
4889 packages = pm.getInstalledPackagesAsUser(
4890 PackageManager.MATCH_DISABLED_COMPONENTS
chen xuf7e9fe82019-05-09 19:31:02 -07004891 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4892 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08004893 }
4894 for (int p = packages.size() - 1; p >= 0; p--) {
4895 PackageInfo pkgInfo = packages.get(p);
4896 if (pkgInfo != null && pkgInfo.packageName != null
4897 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07004898 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08004899 privilegedPackages.add(pkgInfo.packageName);
4900 }
4901 }
4902 }
4903 }
4904 return privilegedPackages;
4905 }
4906
chen xuf7e9fe82019-05-09 19:31:02 -07004907 @Override
4908 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
4909 List<String> privilegedPackages = new ArrayList<>();
4910 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4911 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
4912 }
4913 return privilegedPackages;
4914 }
4915
Wink Savilleb564aae2014-10-23 10:18:09 -07004916 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004917 final Phone phone = getPhone(subId);
4918 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004919 if (card == null) {
4920 loge("getIccId: No UICC");
4921 return null;
4922 }
4923 String iccId = card.getIccId();
4924 if (TextUtils.isEmpty(iccId)) {
4925 loge("getIccId: ICC ID is null or empty.");
4926 return null;
4927 }
4928 return iccId;
4929 }
4930
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004931 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004932 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4933 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004934 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4935 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004936
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004937 final long identity = Binder.clearCallingIdentity();
4938 try {
4939 final String iccId = getIccId(subId);
4940 final Phone phone = getPhone(subId);
4941 if (phone == null) {
4942 return false;
4943 }
4944 final String subscriberId = phone.getSubscriberId();
4945
4946 if (DBG_MERGE) {
4947 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4948 + subscriberId + " to " + number);
4949 }
4950
4951 if (TextUtils.isEmpty(iccId)) {
4952 return false;
4953 }
4954
4955 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4956
4957 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4958 if (alphaTag == null) {
4959 editor.remove(alphaTagPrefKey);
4960 } else {
4961 editor.putString(alphaTagPrefKey, alphaTag);
4962 }
4963
4964 // Record both the line number and IMSI for this ICCID, since we need to
4965 // track all merged IMSIs based on line number
4966 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4967 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4968 if (number == null) {
4969 editor.remove(numberPrefKey);
4970 editor.remove(subscriberPrefKey);
4971 } else {
4972 editor.putString(numberPrefKey, number);
4973 editor.putString(subscriberPrefKey, subscriberId);
4974 }
4975
4976 editor.commit();
4977 return true;
4978 } finally {
4979 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004980 }
Derek Tan7226c842014-07-02 17:42:23 -07004981 }
4982
4983 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004984 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004985 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004986 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004987 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004988 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004989 return null;
4990 }
Derek Tan97ebb422014-09-05 16:55:38 -07004991
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004992 final long identity = Binder.clearCallingIdentity();
4993 try {
4994 String iccId = getIccId(subId);
4995 if (iccId != null) {
4996 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4997 if (DBG_MERGE) {
4998 log("getLine1NumberForDisplay returning "
4999 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5000 }
5001 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005002 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005003 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5004 return null;
5005 } finally {
5006 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005007 }
Derek Tan7226c842014-07-02 17:42:23 -07005008 }
5009
5010 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005011 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005012 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005013 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005014 return null;
5015 }
Derek Tan97ebb422014-09-05 16:55:38 -07005016
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005017 final long identity = Binder.clearCallingIdentity();
5018 try {
5019 String iccId = getIccId(subId);
5020 if (iccId != null) {
5021 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5022 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5023 }
5024 return null;
5025 } finally {
5026 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005027 }
Derek Tan7226c842014-07-02 17:42:23 -07005028 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005029
5030 @Override
Jordan Liub49b04b2019-05-06 14:45:15 -07005031 public String[] getMergedSubscriberIds(int subId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005032 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5033 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005034 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005035 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
5036 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005037 return null;
5038 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005039
Jordan Liub49b04b2019-05-06 14:45:15 -07005040 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5041 // the process, where TelephonyManager was instantiated.
5042 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005043 final long identity = Binder.clearCallingIdentity();
5044 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005045 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005046 final TelephonyManager tele = TelephonyManager.from(context);
5047 final SubscriptionManager sub = SubscriptionManager.from(context);
5048
5049 // Figure out what subscribers are currently active
5050 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005051
Jordan Liub49b04b2019-05-06 14:45:15 -07005052 // Only consider subs which match the current subId
5053 // This logic can be simplified. See b/131189269 for progress.
5054 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005055 activeSubscriberIds.add(tele.getSubscriberId(subId));
5056 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005057
5058 // First pass, find a number override for an active subscriber
5059 String mergeNumber = null;
5060 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5061 for (String key : prefs.keySet()) {
5062 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5063 final String subscriberId = (String) prefs.get(key);
5064 if (activeSubscriberIds.contains(subscriberId)) {
5065 final String iccId = key.substring(
5066 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5067 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5068 mergeNumber = (String) prefs.get(numberKey);
5069 if (DBG_MERGE) {
5070 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5071 + " for active subscriber " + subscriberId);
5072 }
5073 if (!TextUtils.isEmpty(mergeNumber)) {
5074 break;
5075 }
5076 }
5077 }
5078 }
5079
5080 // Shortcut when no active merged subscribers
5081 if (TextUtils.isEmpty(mergeNumber)) {
5082 return null;
5083 }
5084
5085 // Second pass, find all subscribers under that line override
5086 final ArraySet<String> result = new ArraySet<>();
5087 for (String key : prefs.keySet()) {
5088 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5089 final String number = (String) prefs.get(key);
5090 if (mergeNumber.equals(number)) {
5091 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5092 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5093 final String subscriberId = (String) prefs.get(subscriberKey);
5094 if (!TextUtils.isEmpty(subscriberId)) {
5095 result.add(subscriberId);
5096 }
5097 }
5098 }
5099 }
5100
5101 final String[] resultArray = result.toArray(new String[result.size()]);
5102 Arrays.sort(resultArray);
5103 if (DBG_MERGE) {
5104 Slog.d(LOG_TAG,
5105 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5106 }
5107 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005108 } finally {
5109 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005110 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005111 }
5112
5113 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005114 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005115 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5116 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005117
5118 final long identity = Binder.clearCallingIdentity();
5119 try {
5120 final Phone phone = getPhone(subId);
5121 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5122 } finally {
5123 Binder.restoreCallingIdentity(identity);
5124 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005125 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005126
5127 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005128 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005129 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5130 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005131 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005132
5133 final long identity = Binder.clearCallingIdentity();
5134 try {
5135 final Phone phone = getPhone(subId);
5136 if (phone == null) {
5137 return false;
5138 }
5139 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5140 cdmaNonRoamingList);
5141 } finally {
5142 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005143 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005144 }
5145
5146 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005147 @Deprecated
5148 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5149 enforceModifyPermission();
5150
5151 int returnValue = 0;
5152 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005153 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005154 if(result.exception == null) {
5155 if (result.result != null) {
5156 byte[] responseData = (byte[])(result.result);
5157 if(responseData.length > oemResp.length) {
5158 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5159 responseData.length + "bytes. Buffer Size is " +
5160 oemResp.length + "bytes.");
5161 }
5162 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5163 returnValue = responseData.length;
5164 }
5165 } else {
5166 CommandException ex = (CommandException) result.exception;
5167 returnValue = ex.getCommandError().ordinal();
5168 if(returnValue > 0) returnValue *= -1;
5169 }
5170 } catch (RuntimeException e) {
5171 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5172 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5173 if(returnValue > 0) returnValue *= -1;
5174 }
5175
5176 return returnValue;
5177 }
5178
5179 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005180 public void setRadioCapability(RadioAccessFamily[] rafs) {
5181 try {
5182 ProxyController.getInstance().setRadioCapability(rafs);
5183 } catch (RuntimeException e) {
5184 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5185 }
5186 }
5187
5188 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005189 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005190 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005191 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005192 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005193 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005194 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005195 final long identity = Binder.clearCallingIdentity();
5196 try {
chen xub97461a2018-10-26 14:17:57 -07005197 TelephonyPermissions
5198 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5199 mApp, phone.getSubId(), "getRadioAccessFamily");
5200 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005201 } finally {
5202 Binder.restoreCallingIdentity(identity);
5203 }
chen xub97461a2018-10-26 14:17:57 -07005204 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005205 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005206
5207 @Override
5208 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005209 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005210 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005211
5212 final long identity = Binder.clearCallingIdentity();
5213 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005214 ImsManager.getInstance(defaultPhone.getContext(),
5215 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005216 } finally {
5217 Binder.restoreCallingIdentity(identity);
5218 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005219 }
5220
5221 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005222 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005223 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00005224 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005225 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005226 return false;
5227 }
Svet Ganovb320e182015-04-16 12:30:10 -07005228
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005229 final long identity = Binder.clearCallingIdentity();
5230 try {
5231 // Check the user preference and the system-level IMS setting. Even if the user has
5232 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5233 // In the long run, we may instead need to check if there exists a connection service
5234 // which can support video calling.
5235 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005236 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005237 return imsManager.isVtEnabledByPlatform()
5238 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5239 && imsManager.isVtEnabledByUser();
5240 } finally {
5241 Binder.restoreCallingIdentity(identity);
5242 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005243 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005244
Andrew Leea1239f22015-03-02 17:44:07 -08005245 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005246 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
5247 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5248 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5249 return false;
5250 }
5251
5252 final long identity = Binder.clearCallingIdentity();
5253 try {
5254 CarrierConfigManager configManager =
5255 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005256 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005257 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5258 } finally {
5259 Binder.restoreCallingIdentity(identity);
5260 }
Andrew Leea1239f22015-03-02 17:44:07 -08005261 }
5262
5263 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005264 public boolean isWorldPhone(int subId, String callingPackage) {
5265 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5266 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5267 return false;
5268 }
5269
5270 final long identity = Binder.clearCallingIdentity();
5271 try {
5272 CarrierConfigManager configManager =
5273 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005274 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005275 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5276 } finally {
5277 Binder.restoreCallingIdentity(identity);
5278 }
Andrew Leea1239f22015-03-02 17:44:07 -08005279 }
5280
Andrew Lee9431b832015-03-09 18:46:45 -07005281 @Override
5282 public boolean isTtyModeSupported() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005283 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005284 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005285 }
5286
5287 @Override
5288 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005289 final long identity = Binder.clearCallingIdentity();
5290 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005291 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005292 } finally {
5293 Binder.restoreCallingIdentity(identity);
5294 }
Andrew Lee9431b832015-03-09 18:46:45 -07005295 }
5296
Hall Liuf6668912018-10-31 17:05:23 -07005297 /**
5298 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5299 * support for the feature and device firmware support.
5300 *
5301 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5302 */
5303 @Override
5304 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005305 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005306 final Phone phone = getPhone(subscriptionId);
5307 if (phone == null) {
5308 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5309 return false;
5310 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005311 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005312 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005313 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5314 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005315 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005316 return isCarrierSupported && isDeviceSupported;
5317 } finally {
5318 Binder.restoreCallingIdentity(identity);
5319 }
Hall Liu98187582018-01-22 19:15:32 -08005320 }
5321
Hall Liuf6668912018-10-31 17:05:23 -07005322 /**
Hall Liu6a06be62019-07-23 18:39:00 -07005323 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
5324 * RTT setting, will return true if the device and carrier both support RTT.
5325 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07005326 */
5327 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005328 final long identity = Binder.clearCallingIdentity();
5329 try {
Hall Liu6a06be62019-07-23 18:39:00 -07005330 boolean isRttSupported = isRttSupported(subscriptionId);
5331 boolean isUserRttSettingOn = Settings.Secure.getInt(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005332 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Hall Liu6a06be62019-07-23 18:39:00 -07005333 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
5334 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
5335 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005336 } finally {
5337 Binder.restoreCallingIdentity(identity);
5338 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005339 }
5340
Sanket Padawe7310cc72015-01-14 09:53:20 -08005341 /**
5342 * Returns the unique device ID of phone, for example, the IMEI for
5343 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5344 *
5345 * <p>Requires Permission:
5346 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5347 */
5348 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005349 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005350 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005351 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005352 return null;
5353 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005354 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005355 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
5356 callingPackage, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005357 return null;
5358 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005359
5360 final long identity = Binder.clearCallingIdentity();
5361 try {
5362 return phone.getDeviceId();
5363 } finally {
5364 Binder.restoreCallingIdentity(identity);
5365 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005366 }
5367
Ping Sunc67b7c22016-03-02 19:16:45 +08005368 /**
5369 * {@hide}
5370 * Returns the IMS Registration Status on a particular subid
5371 *
5372 * @param subId
5373 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005374 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005375 Phone phone = getPhone(subId);
5376 if (phone != null) {
5377 return phone.isImsRegistered();
5378 } else {
5379 return false;
5380 }
5381 }
5382
Santos Cordon7a1885b2015-02-03 11:15:19 -08005383 @Override
5384 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005385 final long identity = Binder.clearCallingIdentity();
5386 try {
5387 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5388 } finally {
5389 Binder.restoreCallingIdentity(identity);
5390 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005391 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005392
Tyler Gunnf70ed162019-04-03 15:28:53 -07005393 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07005394 public int getSubIdForPhoneAccountHandle(
5395 PhoneAccountHandle phoneAccountHandle, String callingPackage) {
5396 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
5397 callingPackage, "getSubIdForPhoneAccountHandle")) {
5398 throw new SecurityException("Requires READ_PHONE_STATE permission.");
5399 }
5400 final long identity = Binder.clearCallingIdentity();
5401 try {
5402 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
5403 } finally {
5404 Binder.restoreCallingIdentity(identity);
5405 }
5406 }
5407
5408 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07005409 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5410 final long identity = Binder.clearCallingIdentity();
5411 try {
5412 Phone phone = getPhone(subscriptionId);
5413 if (phone == null) {
5414 return null;
5415 }
5416 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5417 } finally {
5418 Binder.restoreCallingIdentity(identity);
5419 }
5420 }
5421
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005422 /**
5423 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005424 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005425 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005426 final long identity = Binder.clearCallingIdentity();
5427 try {
5428 Phone phone = getPhone(subId);
5429 if (phone != null) {
5430 return phone.isWifiCallingEnabled();
5431 } else {
5432 return false;
5433 }
5434 } finally {
5435 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005436 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005437 }
5438
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005439 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005440 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005441 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005442 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005443 final long identity = Binder.clearCallingIdentity();
5444 try {
5445 Phone phone = getPhone(subId);
5446 if (phone != null) {
5447 return phone.isVideoEnabled();
5448 } else {
5449 return false;
5450 }
5451 } finally {
5452 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005453 }
5454 }
5455
5456 /**
5457 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5458 * defined in {@link ImsRegistrationImplBase}.
5459 */
5460 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005461 final long identity = Binder.clearCallingIdentity();
5462 try {
5463 Phone phone = getPhone(subId);
5464 if (phone != null) {
5465 return phone.getImsRegistrationTech();
5466 } else {
5467 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5468 }
5469 } finally {
5470 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005471 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005472 }
5473
Stuart Scott8eef64f2015-04-08 15:13:54 -07005474 @Override
5475 public void factoryReset(int subId) {
5476 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005477 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5478 return;
5479 }
5480
Svet Ganovcc087f82015-05-12 20:35:54 -07005481 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005482
Svet Ganovcc087f82015-05-12 20:35:54 -07005483 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005484 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5485 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005486 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005487 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005488 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005489 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5490 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005491 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005492 // There has been issues when Sms raw table somehow stores orphan
5493 // fragments. They lead to garbled message when new fragments come
5494 // in and combined with those stale ones. In case this happens again,
5495 // user can reset all network settings which will clean up this table.
5496 cleanUpSmsRawTable(getDefaultPhone().getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07005497 } finally {
5498 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005499 }
5500 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005501
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005502 private void cleanUpSmsRawTable(Context context) {
5503 ContentResolver resolver = context.getContentResolver();
5504 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5505 resolver.delete(uri, null, null);
5506 }
5507
Narayan Kamath1c496c22015-04-16 14:40:19 +01005508 @Override
chen xu5d3637b2019-01-21 23:31:38 -08005509 public String getSimLocaleForSubscriber(int subId) {
5510 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5511 final Phone phone = getPhone(subId);
5512 if (phone == null) {
5513 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08005514 return null;
chen xu5d3637b2019-01-21 23:31:38 -08005515 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005516 final long identity = Binder.clearCallingIdentity();
5517 try {
chen xu5d3637b2019-01-21 23:31:38 -08005518 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5519 phone.getContext().getOpPackageName());
chen xu6291c472019-02-04 12:55:53 -08005520 if (info == null) {
5521 log("getSimLocaleForSubscriber, inactive subId: " + subId);
5522 return null;
5523 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005524 // Try and fetch the locale from the carrier properties or from the SIM language
5525 // preferences (EF-PL and EF-LI)...
5526 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005527 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08005528 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5529 if (localeFromDefaultSim != null) {
5530 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5531 if (DBG) log("Using locale from subId: " + subId + " locale: "
5532 + localeFromDefaultSim);
5533 return localeFromDefaultSim.toLanguageTag();
5534 } else {
5535 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005536 }
5537 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005538
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005539 // The SIM language preferences only store a language (e.g. fr = French), not an
5540 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5541 // the SIM and carrier preferences does not include a country we add the country
5542 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005543 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005544 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08005545 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005546 return mccLocale.toLanguageTag();
5547 }
5548
5549 if (DBG) log("No locale found - returning null");
5550 return null;
5551 } finally {
5552 Binder.restoreCallingIdentity(identity);
5553 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005554 }
5555
5556 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005557 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005558 }
5559
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005560 /**
5561 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5562 */
5563 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005564 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005565 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005566
Chenjie Yu1ba97252018-01-11 18:16:20 -08005567 private final ModemActivityInfo mLastModemActivityInfo =
5568 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
5569
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005570 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005571 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5572 * representing the state of the modem.
5573 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005574 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5575 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005576 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005577 */
5578 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005579 public void requestModemActivityInfo(ResultReceiver result) {
5580 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005581 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005582
5583 final long identity = Binder.clearCallingIdentity();
5584 try {
5585 ModemActivityInfo ret = null;
5586 synchronized (mLastModemActivityInfo) {
5587 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5588 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07005589 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07005590 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005591 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
5592 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005593 mergedTxTimeMs[i] = info.getTxTimeMillis()[i]
5594 + mLastModemActivityInfo.getTxTimeMillis()[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005595 }
5596 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005597 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
5598 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005599 mLastModemActivityInfo.setIdleTimeMillis(
5600 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
5601 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
5602 mLastModemActivityInfo.setRxTimeMillis(
5603 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
5604 mLastModemActivityInfo.setEnergyUsed(
5605 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005606 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005607 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
5608 mLastModemActivityInfo.getSleepTimeMillis(),
5609 mLastModemActivityInfo.getIdleTimeMillis(),
5610 mLastModemActivityInfo.getTxTimeMillis(),
5611 mLastModemActivityInfo.getRxTimeMillis(),
5612 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005613 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005614 Bundle bundle = new Bundle();
5615 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
5616 result.send(0, bundle);
5617 } finally {
5618 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005619 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005620 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005621
Siddharth Rayb8114062018-06-17 15:02:38 -07005622 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
5623 // less than total activity duration.
5624 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
5625 if (info == null) {
5626 return false;
5627 }
5628 int activityDurationMs =
5629 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
5630 int totalTxTimeMs = 0;
5631 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
5632 totalTxTimeMs += info.getTxTimeMillis()[i];
5633 }
5634 return (info.isValid()
5635 && (info.getSleepTimeMillis() <= activityDurationMs)
5636 && (info.getIdleTimeMillis() <= activityDurationMs)
5637 && (info.getRxTimeMillis() <= activityDurationMs)
5638 && (totalTxTimeMs <= activityDurationMs));
5639 }
5640
Jack Yu85bd38a2015-11-09 11:34:32 -08005641 /**
5642 * {@hide}
5643 * Returns the service state information on specified subscription.
5644 */
5645 @Override
5646 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005647 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005648 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08005649 return null;
5650 }
5651
Hall Liuf19c44f2018-11-27 14:38:17 -08005652 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
5653 LocationAccessPolicy.checkLocationPermission(mApp,
5654 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5655 .setCallingPackage(callingPackage)
5656 .setCallingPid(Binder.getCallingPid())
5657 .setCallingUid(Binder.getCallingUid())
5658 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07005659 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005660 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5661 .build());
5662
5663 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
5664 LocationAccessPolicy.checkLocationPermission(mApp,
5665 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5666 .setCallingPackage(callingPackage)
5667 .setCallingPid(Binder.getCallingPid())
5668 .setCallingUid(Binder.getCallingUid())
5669 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07005670 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005671 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5672 .build());
5673 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
5674 boolean hasFinePermission =
5675 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5676 boolean hasCoarsePermission =
5677 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5678
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005679 final long identity = Binder.clearCallingIdentity();
5680 try {
5681 final Phone phone = getPhone(subId);
5682 if (phone == null) {
5683 return null;
5684 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005685
Hall Liuf19c44f2018-11-27 14:38:17 -08005686 ServiceState ss = phone.getServiceState();
5687
5688 // Scrub out the location info in ServiceState depending on what level of access
5689 // the caller has.
5690 if (hasFinePermission) return ss;
5691 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
5692 return ss.sanitizeLocationInfo(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005693 } finally {
5694 Binder.restoreCallingIdentity(identity);
5695 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005696 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005697
5698 /**
5699 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
5700 *
5701 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5702 * voicemail ringtone.
5703 * @return The URI for the ringtone to play when receiving a voicemail from a specific
5704 * PhoneAccount.
5705 */
5706 @Override
5707 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005708 final long identity = Binder.clearCallingIdentity();
5709 try {
5710 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5711 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005712 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005713 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005714
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005715 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
5716 } finally {
5717 Binder.restoreCallingIdentity(identity);
5718 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005719 }
5720
5721 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005722 * Sets the per-account voicemail ringtone.
5723 *
5724 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5725 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5726 *
5727 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5728 * voicemail ringtone.
5729 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5730 * PhoneAccount.
5731 */
5732 @Override
5733 public void setVoicemailRingtoneUri(String callingPackage,
5734 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005735 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005736 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5737 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005738 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005739 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5740 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5741 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005742 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005743
5744 final long identity = Binder.clearCallingIdentity();
5745 try {
5746 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5747 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005748 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005749 }
5750 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5751 } finally {
5752 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005753 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005754 }
5755
5756 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005757 * Returns whether vibration is set for voicemail notification in Phone settings.
5758 *
5759 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5760 * voicemail vibration setting.
5761 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5762 */
5763 @Override
5764 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005765 final long identity = Binder.clearCallingIdentity();
5766 try {
5767 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5768 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005769 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005770 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005771
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005772 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5773 } finally {
5774 Binder.restoreCallingIdentity(identity);
5775 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005776 }
5777
Youhan Wange64578a2016-05-02 15:32:42 -07005778 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005779 * Sets the per-account voicemail vibration.
5780 *
5781 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5782 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5783 *
5784 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5785 * voicemail vibration setting.
5786 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5787 * specific PhoneAccount.
5788 */
5789 @Override
5790 public void setVoicemailVibrationEnabled(String callingPackage,
5791 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005792 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005793 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5794 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005795 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005796 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5797 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5798 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005799 }
5800
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005801 final long identity = Binder.clearCallingIdentity();
5802 try {
5803 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5804 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005805 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005806 }
5807 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5808 } finally {
5809 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005810 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005811 }
5812
5813 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005814 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5815 *
5816 * @throws SecurityException if the caller does not have the required permission
5817 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005818 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005819 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07005820 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005821 }
5822
5823 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005824 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5825 * permission.
5826 *
5827 * @throws SecurityException if the caller does not have the required permission
5828 */
5829 private void enforceSendSmsPermission() {
5830 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5831 }
5832
5833 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005834 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005835 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005836 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005837 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005838 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005839 final long identity = Binder.clearCallingIdentity();
5840 try {
5841 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005842 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005843 if (componentName == null) {
5844 throw new SecurityException(
5845 "Caller not current active visual voicemail package[null]");
5846 }
5847 String vvmPackage = componentName.getPackageName();
5848 if (!callingPackage.equals(vvmPackage)) {
5849 throw new SecurityException("Caller not current active visual voicemail package["
5850 + vvmPackage + "]");
5851 }
5852 } finally {
5853 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005854 }
5855 }
5856
5857 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005858 * Return the application ID for the app type.
5859 *
5860 * @param subId the subscription ID that this request applies to.
5861 * @param appType the uicc app type.
5862 * @return Application ID for specificied app type, or null if no uicc.
5863 */
5864 @Override
5865 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005866 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005867 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005868
5869 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005870 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005871 if (phone == null) {
5872 return null;
5873 }
5874 String aid = null;
5875 try {
5876 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5877 .getApplicationByType(appType).getAid();
5878 } catch (Exception e) {
5879 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5880 }
5881 return aid;
5882 } finally {
5883 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005884 }
Youhan Wange64578a2016-05-02 15:32:42 -07005885 }
5886
Youhan Wang4001d252016-05-11 10:29:41 -07005887 /**
5888 * Return the Electronic Serial Number.
5889 *
5890 * @param subId the subscription ID that this request applies to.
5891 * @return ESN or null if error.
5892 */
5893 @Override
5894 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005895 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005896 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005897
5898 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005899 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005900 if (phone == null) {
5901 return null;
5902 }
5903 String esn = null;
5904 try {
5905 esn = phone.getEsn();
5906 } catch (Exception e) {
5907 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5908 }
5909 return esn;
5910 } finally {
5911 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005912 }
Youhan Wang4001d252016-05-11 10:29:41 -07005913 }
5914
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005915 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005916 * Return the Preferred Roaming List Version.
5917 *
5918 * @param subId the subscription ID that this request applies to.
5919 * @return PRLVersion or null if error.
5920 */
5921 @Override
5922 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005923 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005924 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005925
5926 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005927 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005928 if (phone == null) {
5929 return null;
5930 }
5931 String cdmaPrlVersion = null;
5932 try {
5933 cdmaPrlVersion = phone.getCdmaPrlVersion();
5934 } catch (Exception e) {
5935 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5936 }
5937 return cdmaPrlVersion;
5938 } finally {
5939 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005940 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005941 }
5942
5943 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005944 * Get snapshot of Telephony histograms
5945 * @return List of Telephony histograms
5946 * @hide
5947 */
5948 @Override
5949 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005950 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5951 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005952
5953 final long identity = Binder.clearCallingIdentity();
5954 try {
5955 return RIL.getTelephonyRILTimingHistograms();
5956 } finally {
5957 Binder.restoreCallingIdentity(identity);
5958 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005959 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005960
5961 /**
5962 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08005963 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
5964 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005965 * Require system privileges. In the future we may add this to carrier APIs.
5966 *
Michele Berionne482f8202018-11-27 18:57:59 -08005967 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005968 */
5969 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08005970 @TelephonyManager.SetCarrierRestrictionResult
5971 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005972 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005973 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005974
Michele Berionne482f8202018-11-27 18:57:59 -08005975 if (carrierRestrictionRules == null) {
5976 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08005977 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005978
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005979 final long identity = Binder.clearCallingIdentity();
5980 try {
Michele Berionne482f8202018-11-27 18:57:59 -08005981 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07005982 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005983 } finally {
5984 Binder.restoreCallingIdentity(identity);
5985 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005986 }
5987
5988 /**
5989 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08005990 * Get the allowed carrier list and the excluded carrier list, including the priority between
5991 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005992 * Require system privileges. In the future we may add this to carrier APIs.
5993 *
Michele Berionne482f8202018-11-27 18:57:59 -08005994 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07005995 */
5996 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08005997 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005998 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07005999 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006000
6001 final long identity = Binder.clearCallingIdentity();
6002 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006003 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
6004 if (response instanceof CarrierRestrictionRules) {
6005 return (CarrierRestrictionRules) response;
6006 }
6007 // Response is an Exception of some kind,
6008 // which is signalled to the user as a NULL retval
6009 return null;
6010 } catch (Exception e) {
6011 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
6012 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006013 } finally {
6014 Binder.restoreCallingIdentity(identity);
6015 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006016 }
6017
fionaxu59545b42016-05-25 15:53:37 -07006018 /**
6019 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
6020 * @param subId the subscription ID that this action applies to.
6021 * @param enabled control enable or disable metered apns.
6022 * {@hide}
6023 */
6024 @Override
6025 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
6026 enforceModifyPermission();
6027 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006028
6029 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006030 if (phone == null) {
6031 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
6032 return;
6033 }
6034 try {
6035 phone.carrierActionSetMeteredApnsEnabled(enabled);
6036 } catch (Exception e) {
6037 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006038 } finally {
6039 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006040 }
6041 }
6042
6043 /**
6044 * Action set from carrier signalling broadcast receivers to enable/disable radio
6045 * @param subId the subscription ID that this action applies to.
6046 * @param enabled control enable or disable radio.
6047 * {@hide}
6048 */
6049 @Override
6050 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
6051 enforceModifyPermission();
6052 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006053
6054 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006055 if (phone == null) {
6056 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
6057 return;
6058 }
6059 try {
6060 phone.carrierActionSetRadioEnabled(enabled);
6061 } catch (Exception e) {
6062 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006063 } finally {
6064 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006065 }
6066 }
6067
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006068 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006069 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6070 * network status based on which carrier apps could apply actions accordingly,
6071 * enable/disable default url handler for example.
6072 *
6073 * @param subId the subscription ID that this action applies to.
6074 * @param report control start/stop reporting the default network status.
6075 * {@hide}
6076 */
6077 @Override
6078 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6079 enforceModifyPermission();
6080 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006081
6082 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006083 if (phone == null) {
6084 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6085 return;
6086 }
6087 try {
6088 phone.carrierActionReportDefaultNetworkStatus(report);
6089 } catch (Exception e) {
6090 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006091 } finally {
6092 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006093 }
6094 }
6095
6096 /**
fionaxud9622282017-07-17 17:51:30 -07006097 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6098 * @param subId the subscription ID that this action applies to.
6099 * {@hide}
6100 */
6101 @Override
6102 public void carrierActionResetAll(int subId) {
6103 enforceModifyPermission();
6104 final Phone phone = getPhone(subId);
6105 if (phone == null) {
6106 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6107 return;
6108 }
6109 try {
6110 phone.carrierActionResetAll();
6111 } catch (Exception e) {
6112 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6113 }
6114 }
6115
6116 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006117 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6118 * bug report is being generated.
6119 */
6120 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006121 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006122 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6123 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006124 writer.println("Permission Denial: can't dump Phone from pid="
6125 + Binder.getCallingPid()
6126 + ", uid=" + Binder.getCallingUid()
6127 + "without permission "
6128 + android.Manifest.permission.DUMP);
6129 return;
6130 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006131 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006132 }
Jack Yueb89b242016-06-22 13:27:47 -07006133
Brad Ebingerdac2f002018-04-03 15:17:52 -07006134 @Override
6135 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6136 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6137 throws RemoteException {
6138 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
6139 }
6140
Jack Yueb89b242016-06-22 13:27:47 -07006141 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006142 * Get aggregated video call data usage since boot.
6143 *
6144 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6145 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006146 * {@hide}
6147 */
6148 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006149 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006150 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6151 null);
6152
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006153 final long identity = Binder.clearCallingIdentity();
6154 try {
6155 // NetworkStatsService keeps tracking the active network interface and identity. It
6156 // records the delta with the corresponding network identity.
6157 // We just return the total video call data usage snapshot since boot.
6158 Phone phone = getPhone(subId);
6159 if (phone != null) {
6160 return phone.getVtDataUsage(perUidStats);
6161 }
6162 return null;
6163 } finally {
6164 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006165 }
Jack Yueb89b242016-06-22 13:27:47 -07006166 }
Jack Yu75ab2952016-07-08 14:29:33 -07006167
6168 /**
6169 * Policy control of data connection. Usually used when data limit is passed.
6170 * @param enabled True if enabling the data, otherwise disabling.
6171 * @param subId Subscription index
6172 * {@hide}
6173 */
6174 @Override
6175 public void setPolicyDataEnabled(boolean enabled, int subId) {
6176 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006177
6178 final long identity = Binder.clearCallingIdentity();
6179 try {
6180 Phone phone = getPhone(subId);
6181 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006182 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006183 }
6184 } finally {
6185 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006186 }
6187 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006188
6189 /**
6190 * Get Client request stats
6191 * @return List of Client Request Stats
6192 * @hide
6193 */
6194 @Override
6195 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006196 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006197 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006198 return null;
6199 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006200 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006201
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006202 final long identity = Binder.clearCallingIdentity();
6203 try {
6204 if (phone != null) {
6205 return phone.getClientRequestStats();
6206 }
6207
6208 return null;
6209 } finally {
6210 Binder.restoreCallingIdentity(identity);
6211 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006212 }
6213
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006214 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006215 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006216 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006217 }
Jack Yueb4124c2017-02-16 15:32:43 -08006218
6219 /**
Grace Chen70990072017-03-24 17:21:30 -07006220 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006221 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006222 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006223 * @param state State of SIM (power down, power up, pass through)
6224 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6225 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6226 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006227 *
6228 **/
6229 @Override
Grace Chen70990072017-03-24 17:21:30 -07006230 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006231 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006232 Phone phone = PhoneFactory.getPhone(slotIndex);
6233
vagdeviaf9a5b92018-08-15 16:01:53 -07006234 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6235
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006236 final long identity = Binder.clearCallingIdentity();
6237 try {
6238 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006239 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006240 }
6241 } finally {
6242 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006243 }
6244 }
Shuo Qiandd210312017-04-12 22:11:33 +00006245
Tyler Gunn65d45c22017-06-05 11:22:26 -07006246 private boolean isUssdApiAllowed(int subId) {
6247 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006248 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006249 if (configManager == null) {
6250 return false;
6251 }
6252 PersistableBundle pb = configManager.getConfigForSubId(subId);
6253 if (pb == null) {
6254 return false;
6255 }
6256 return pb.getBoolean(
6257 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6258 }
6259
Shuo Qiandd210312017-04-12 22:11:33 +00006260 /**
6261 * Check if phone is in emergency callback mode
6262 * @return true if phone is in emergency callback mode
6263 * @param subId sub id
6264 */
goneil9c5f4872017-12-05 14:07:56 -08006265 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006266 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006267 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006268 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006269
6270 final long identity = Binder.clearCallingIdentity();
6271 try {
6272 if (phone != null) {
6273 return phone.isInEcm();
6274 } else {
6275 return false;
6276 }
6277 } finally {
6278 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006279 }
6280 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006281
6282 /**
6283 * Get the current signal strength information for the given subscription.
6284 * Because this information is not updated when the device is in a low power state
6285 * it should not be relied-upon to be current.
6286 * @param subId Subscription index
6287 * @return the most recent cached signal strength info from the modem
6288 */
6289 @Override
6290 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006291 final long identity = Binder.clearCallingIdentity();
6292 try {
6293 Phone p = getPhone(subId);
6294 if (p == null) {
6295 return null;
6296 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006297
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006298 return p.getSignalStrength();
6299 } finally {
6300 Binder.restoreCallingIdentity(identity);
6301 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006302 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006303
Pengquan Meng77b7f132018-08-22 14:49:57 -07006304 /**
Chen Xuf792fd62018-10-17 17:54:36 +00006305 * Get the current modem radio state for the given slot.
6306 * @param slotIndex slot index.
6307 * @param callingPackage the name of the package making the call.
6308 * @return the current radio power state from the modem
6309 */
6310 @Override
6311 public int getRadioPowerState(int slotIndex, String callingPackage) {
6312 Phone phone = PhoneFactory.getPhone(slotIndex);
6313 if (phone != null) {
6314 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6315 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
6316 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6317 }
6318
6319 final long identity = Binder.clearCallingIdentity();
6320 try {
6321 return phone.getRadioPowerState();
6322 } finally {
6323 Binder.restoreCallingIdentity(identity);
6324 }
6325 }
6326 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6327 }
6328
6329 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07006330 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6331 *
6332 * <p>Requires one of the following permissions:
6333 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6334 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6335 * privileges.
6336 *
6337 * @param subId subscription id
6338 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6339 * {@code false}.
6340 */
6341 @Override
6342 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006343 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6344 null /* message */);
6345
Pengquan Menga1bb6272018-09-06 09:59:22 -07006346 boolean isEnabled = false;
6347 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07006348 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006349 Phone phone = getPhone(subId);
6350 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006351 } catch (Exception e) {
6352 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6353 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07006354 } finally {
6355 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006356 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006357 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006358 }
6359
6360
6361 /**
6362 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6363 *
6364 * <p> Requires permission:
6365 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6366 * privileges.
6367 *
6368 * @param subId subscription id
6369 * @param isEnabled {@code true} means enable, {@code false} means disable.
6370 */
6371 @Override
6372 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006373 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6374 mApp, subId, "setDataRoamingEnabled");
6375
Pengquan Menga1bb6272018-09-06 09:59:22 -07006376 final long identity = Binder.clearCallingIdentity();
6377 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006378 Phone phone = getPhone(subId);
6379 if (phone != null) {
6380 phone.setDataRoamingEnabled(isEnabled);
6381 }
6382 } finally {
6383 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006384 }
6385 }
6386
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006387 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006388 public boolean isManualNetworkSelectionAllowed(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006389 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6390 mApp, subId, "isManualNetworkSelectionAllowed");
6391
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006392 boolean isAllowed = true;
6393 final long identity = Binder.clearCallingIdentity();
6394 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006395 Phone phone = getPhone(subId);
6396 if (phone != null) {
6397 isAllowed = phone.isCspPlmnEnabled();
6398 }
6399 } finally {
6400 Binder.restoreCallingIdentity(identity);
6401 }
6402 return isAllowed;
6403 }
6404
6405 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006406 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006407 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08006408 try {
6409 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07006410 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08006411 } catch (SecurityException e) {
6412 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6413 // has carrier privileges on an active UICC
6414 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6415 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006416 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08006417 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006418 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006419
6420 final long identity = Binder.clearCallingIdentity();
6421 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006422 UiccController uiccController = UiccController.getInstance();
6423 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07006424 if (hasReadPermission) {
6425 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006426 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07006427
6428 // Remove private info if the caller doesn't have access
6429 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6430 for (UiccCardInfo cardInfo : cardInfos) {
6431 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6432 // is available
6433 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
6434 if (card == null || card.getUiccProfile() == null) {
6435 // assume no access if the card or profile is unavailable
6436 filteredInfos.add(cardInfo.getUnprivileged());
6437 continue;
6438 }
6439 UiccProfile profile = card.getUiccProfile();
6440 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6441 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6442 filteredInfos.add(cardInfo);
6443 } else {
6444 filteredInfos.add(cardInfo.getUnprivileged());
6445 }
6446 }
6447 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08006448 } finally {
6449 Binder.restoreCallingIdentity(identity);
6450 }
6451 }
6452
6453 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006454 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006455 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006456
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006457 final long identity = Binder.clearCallingIdentity();
6458 try {
6459 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6460 if (slots == null) {
6461 Rlog.i(LOG_TAG, "slots is null.");
6462 return null;
6463 }
6464
6465 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6466 for (int i = 0; i < slots.length; i++) {
6467 UiccSlot slot = slots[i];
6468 if (slot == null) {
6469 continue;
6470 }
6471
Jordan Liu7be7e652019-05-06 18:55:02 +00006472 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006473 UiccCard card = slot.getUiccCard();
6474 if (card != null) {
6475 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00006476 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07006477 cardId = slot.getEid();
6478 if (TextUtils.isEmpty(cardId)) {
6479 cardId = slot.getIccId();
6480 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006481 }
6482
Jordan Liu857451f2019-05-09 16:35:35 -07006483 if (cardId != null) {
6484 // if cardId is an ICCID, strip off trailing Fs before exposing to user
6485 // if cardId is an EID, it's all digits so this is fine
6486 cardId = IccUtils.stripTrailingFs(cardId);
6487 }
6488
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006489 int cardState = 0;
6490 switch (slot.getCardState()) {
6491 case CARDSTATE_ABSENT:
6492 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6493 break;
6494 case CARDSTATE_PRESENT:
6495 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6496 break;
6497 case CARDSTATE_ERROR:
6498 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6499 break;
6500 case CARDSTATE_RESTRICTED:
6501 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6502 break;
6503 default:
6504 break;
6505
6506 }
6507
6508 infos[i] = new UiccSlotInfo(
6509 slot.isActive(),
6510 slot.isEuicc(),
6511 cardId,
6512 cardState,
6513 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08006514 slot.isExtendedApduSupported(),
6515 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006516 }
6517 return infos;
6518 } finally {
6519 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006520 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006521 }
6522
6523 @Override
6524 public boolean switchSlots(int[] physicalSlots) {
6525 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006526
6527 final long identity = Binder.clearCallingIdentity();
6528 try {
6529 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6530 } finally {
6531 Binder.restoreCallingIdentity(identity);
6532 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006533 }
Jack Yu4c988042018-02-27 15:30:01 -08006534
6535 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006536 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006537 final long identity = Binder.clearCallingIdentity();
6538 try {
6539 return UiccController.getInstance().getCardIdForDefaultEuicc();
6540 } finally {
6541 Binder.restoreCallingIdentity(identity);
6542 }
6543 }
6544
6545 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006546 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6547 enforceModifyPermission();
6548 final Phone phone = getPhone(subId);
6549 if (phone == null) {
6550 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6551 return;
6552 }
6553
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006554 final long identity = Binder.clearCallingIdentity();
6555 try {
6556 phone.setRadioIndicationUpdateMode(filters, mode);
6557 } finally {
6558 Binder.restoreCallingIdentity(identity);
6559 }
Jack Yu4c988042018-02-27 15:30:01 -08006560 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006561
6562 /**
goneil47ffb6e2018-04-06 15:40:58 -07006563 * A test API to reload the UICC profile.
6564 *
6565 * <p>Requires that the calling app has permission
6566 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6567 * @hide
6568 */
6569 @Override
6570 public void refreshUiccProfile(int subId) {
6571 enforceModifyPermission();
6572
6573 final long identity = Binder.clearCallingIdentity();
6574 try {
6575 Phone phone = getPhone(subId);
6576 if (phone == null) {
6577 return;
6578 }
6579 UiccCard uiccCard = phone.getUiccCard();
6580 if (uiccCard == null) {
6581 return;
6582 }
6583 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6584 if (uiccProfile == null) {
6585 return;
6586 }
6587 uiccProfile.refresh();
6588 } finally {
6589 Binder.restoreCallingIdentity(identity);
6590 }
6591 }
6592
6593 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006594 * Returns false if the mobile data is disabled by default, otherwise return true.
6595 */
6596 private boolean getDefaultDataEnabled() {
6597 return "true".equalsIgnoreCase(
6598 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
6599 }
6600
6601 /**
6602 * Returns true if the data roaming is enabled by default, i.e the system property
6603 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
6604 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
6605 */
6606 private boolean getDefaultDataRoamingEnabled(int subId) {
6607 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006608 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006609 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
6610 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
6611 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
6612 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
6613 return isDataRoamingEnabled;
6614 }
6615
6616 /**
6617 * Returns the default network type for the given {@code subId}, if the default network type is
6618 * not set, return {@link Phone#PREFERRED_NT_MODE}.
6619 */
6620 private int getDefaultNetworkType(int subId) {
6621 return Integer.parseInt(
6622 TelephonyManager.getTelephonyProperty(
6623 mSubscriptionController.getPhoneId(subId),
6624 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
6625 String.valueOf(Phone.PREFERRED_NT_MODE)));
6626 }
fionaxua13278b2018-03-21 00:08:13 -07006627
6628 @Override
6629 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07006630 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07006631 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006632
6633 final long identity = Binder.clearCallingIdentity();
6634 try {
6635 final Phone phone = getPhone(subId);
6636 if (phone == null) {
6637 loge("setCarrierTestOverride fails with invalid subId: " + subId);
6638 return;
6639 }
chen xueaba88a2019-03-15 13:15:10 -07006640 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
6641 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006642 } finally {
6643 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006644 }
fionaxua13278b2018-03-21 00:08:13 -07006645 }
6646
6647 @Override
6648 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006649 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006650
6651 final long identity = Binder.clearCallingIdentity();
6652 try {
6653 final Phone phone = getPhone(subId);
6654 if (phone == null) {
6655 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
6656 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
6657 }
6658 return phone.getCarrierIdListVersion();
6659 } finally {
6660 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006661 }
fionaxua13278b2018-03-21 00:08:13 -07006662 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07006663
6664 @Override
6665 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
6666 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6667 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
6668 return -1;
6669 }
6670
6671 final long identity = Binder.clearCallingIdentity();
6672 try {
6673 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
6674 } finally {
6675 Binder.restoreCallingIdentity(identity);
6676 }
6677 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006678
6679 @Override
6680 public int getCdmaRoamingMode(int subId) {
6681 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6682 mApp, subId, "getCdmaRoamingMode");
6683
6684 final long identity = Binder.clearCallingIdentity();
6685 try {
6686 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
6687 } finally {
6688 Binder.restoreCallingIdentity(identity);
6689 }
6690 }
6691
6692 @Override
6693 public boolean setCdmaRoamingMode(int subId, int mode) {
6694 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6695 mApp, subId, "setCdmaRoamingMode");
6696
6697 final long identity = Binder.clearCallingIdentity();
6698 try {
6699 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
6700 } finally {
6701 Binder.restoreCallingIdentity(identity);
6702 }
6703 }
6704
6705 @Override
6706 public boolean setCdmaSubscriptionMode(int subId, int mode) {
6707 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6708 mApp, subId, "setCdmaSubscriptionMode");
6709
6710 final long identity = Binder.clearCallingIdentity();
6711 try {
6712 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
6713 } finally {
6714 Binder.restoreCallingIdentity(identity);
6715 }
6716 }
Makoto Onukida3bf792018-09-18 16:06:29 -07006717
6718 private void ensureUserRunning(int userId) {
6719 if (!mUserManager.isUserRunning(userId)) {
6720 throw new IllegalStateException("User " + userId + " does not exist or not running");
6721 }
6722 }
6723
6724 /**
6725 * Returns a list of SMS apps on a given user.
6726 *
6727 * Only the shell user (UID 2000 or 0) can call it.
6728 * Target user must be running.
6729 */
6730 @Override
6731 public String[] getSmsApps(int userId) {
6732 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
6733 ensureUserRunning(userId);
6734
6735 final Collection<SmsApplicationData> apps =
6736 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
6737
6738 String[] ret = new String[apps.size()];
6739 int i = 0;
6740 for (SmsApplicationData app : apps) {
6741 ret[i++] = app.mPackageName;
6742 }
6743 return ret;
6744 }
6745
6746 /**
6747 * Returns the default SMS app package name on a given user.
6748 *
6749 * Only the shell user (UID 2000 or 0) can call it.
6750 * Target user must be running.
6751 */
6752 @Override
6753 public String getDefaultSmsApp(int userId) {
6754 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
6755 ensureUserRunning(userId);
6756
6757 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
6758 /* updateIfNeeded= */ true, userId);
6759 return cn == null ? null : cn.getPackageName();
6760 }
6761
6762 /**
6763 * Set a package as the default SMS app on a given user.
6764 *
6765 * Only the shell user (UID 2000 or 0) can call it.
6766 * Target user must be running.
6767 */
6768 @Override
6769 public void setDefaultSmsApp(int userId, String packageName) {
6770 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
6771 ensureUserRunning(userId);
6772
6773 boolean found = false;
6774 for (String pkg : getSmsApps(userId)) {
6775 if (TextUtils.equals(packageName, pkg)) {
6776 found = true;
6777 break;
6778 }
6779 }
6780 if (!found) {
6781 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
6782 }
6783
6784 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
6785 }
sqianc5eccab2018-10-19 18:46:41 -07006786
6787 @Override
sqian8c685422019-02-22 15:55:18 -08006788 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
sqianc5eccab2018-10-19 18:46:41 -07006789 String callingPackage) {
sqian11b7a0e2018-12-05 18:48:28 -08006790 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
sqian8c685422019-02-22 15:55:18 -08006791 mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08006792 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6793 }
6794 final long identity = Binder.clearCallingIdentity();
6795 try {
sqian854d44b2018-12-12 16:48:18 -08006796 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
6797 for (Phone phone: PhoneFactory.getPhones()) {
6798 if (phone.getEmergencyNumberTracker() != null
6799 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
6800 emergencyNumberListInternal.put(
6801 phone.getSubId(),
6802 phone.getEmergencyNumberTracker().getEmergencyNumberList());
6803 }
sqian11b7a0e2018-12-05 18:48:28 -08006804 }
sqian854d44b2018-12-12 16:48:18 -08006805 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08006806 } finally {
6807 Binder.restoreCallingIdentity(identity);
6808 }
sqianc5eccab2018-10-19 18:46:41 -07006809 }
6810
6811 @Override
sqian8c685422019-02-22 15:55:18 -08006812 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006813 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08006814 if (!exactMatch) {
6815 TelephonyPermissions
6816 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08006817 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08006818 }
6819 final long identity = Binder.clearCallingIdentity();
6820 try {
sqian854d44b2018-12-12 16:48:18 -08006821 for (Phone phone: PhoneFactory.getPhones()) {
6822 if (phone.getEmergencyNumberTracker() != null
6823 && phone.getEmergencyNumberTracker() != null) {
6824 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
6825 number, exactMatch)) {
6826 return true;
sqian11b7a0e2018-12-05 18:48:28 -08006827 }
6828 }
sqian11b7a0e2018-12-05 18:48:28 -08006829 }
6830 return false;
6831 } finally {
6832 Binder.restoreCallingIdentity(identity);
6833 }
6834 }
6835
sqianf4ca7ed2019-01-15 18:32:07 -08006836 /**
6837 * Update emergency number list for test mode.
6838 */
6839 @Override
6840 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
6841 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6842 "updateEmergencyNumberListTestMode");
6843
6844 final long identity = Binder.clearCallingIdentity();
6845 try {
6846 for (Phone phone: PhoneFactory.getPhones()) {
6847 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6848 if (tracker != null) {
6849 tracker.executeEmergencyNumberTestModeCommand(action, num);
6850 }
6851 }
6852 } finally {
6853 Binder.restoreCallingIdentity(identity);
6854 }
6855 }
6856
6857 /**
6858 * Get the full emergency number list for test mode.
6859 */
6860 @Override
6861 public List<String> getEmergencyNumberListTestMode() {
6862 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6863 "getEmergencyNumberListTestMode");
6864
6865 final long identity = Binder.clearCallingIdentity();
6866 try {
6867 Set<String> emergencyNumbers = new HashSet<>();
6868 for (Phone phone: PhoneFactory.getPhones()) {
6869 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6870 if (tracker != null) {
6871 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
6872 emergencyNumbers.add(num.getNumber());
6873 }
6874 }
6875 }
6876 return new ArrayList<>(emergencyNumbers);
6877 } finally {
6878 Binder.restoreCallingIdentity(identity);
6879 }
6880 }
6881
chen xud6b45bd2018-10-30 22:27:10 -07006882 @Override
6883 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
6884 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
6885 Phone phone = getPhone(subId);
6886 if (phone == null) {
6887 return null;
6888 }
6889 final long identity = Binder.clearCallingIdentity();
6890 try {
6891 UiccProfile profile = UiccController.getInstance()
6892 .getUiccProfileForPhone(phone.getPhoneId());
6893 if (profile != null) {
6894 return profile.getCertsFromCarrierPrivilegeAccessRules();
6895 }
6896 } finally {
6897 Binder.restoreCallingIdentity(identity);
6898 }
6899 return null;
6900 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08006901
6902 /**
6903 * Enable or disable a modem stack.
6904 */
6905 @Override
6906 public boolean enableModemForSlot(int slotIndex, boolean enable) {
6907 enforceModifyPermission();
6908
6909 final long identity = Binder.clearCallingIdentity();
6910 try {
6911 Phone phone = PhoneFactory.getPhone(slotIndex);
6912 if (phone == null) {
6913 return false;
6914 } else {
6915 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
6916 }
6917 } finally {
6918 Binder.restoreCallingIdentity(identity);
6919 }
6920 }
Michelecea4cf22018-12-21 15:00:11 -08006921
Malcolm Chen4bcd9822019-03-27 18:34:05 -07006922 /**
6923 * Whether a modem stack is enabled or not.
6924 */
6925 @Override
6926 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage) {
6927 Phone phone = PhoneFactory.getPhone(slotIndex);
6928 if (phone == null) return false;
6929
6930 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6931 mApp, phone.getSubId(), callingPackage, "isModemEnabledForSlot")) {
6932 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6933 }
6934
6935 final long identity = Binder.clearCallingIdentity();
6936 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07006937 try {
6938 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
6939 } catch (NoSuchElementException ex) {
6940 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
6941 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07006942 } finally {
6943 Binder.restoreCallingIdentity(identity);
6944 }
6945 }
6946
Michelecea4cf22018-12-21 15:00:11 -08006947 @Override
Michele0ea7d782019-03-19 14:58:42 -07006948 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08006949 enforceModifyPermission();
6950
6951 final long identity = Binder.clearCallingIdentity();
6952 try {
6953 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07006954 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08006955 .commit();
6956 } finally {
6957 Binder.restoreCallingIdentity(identity);
6958 }
6959 }
6960
6961 @Override
Michele0ea7d782019-03-19 14:58:42 -07006962 @TelephonyManager.IsMultiSimSupportedResult
6963 public int isMultiSimSupported(String callingPackage) {
Michele4245e952019-02-04 11:36:23 -08006964 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Michele0ea7d782019-03-19 14:58:42 -07006965 getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) {
6966 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08006967 }
Michelecea4cf22018-12-21 15:00:11 -08006968
6969 final long identity = Binder.clearCallingIdentity();
6970 try {
Michele0ea7d782019-03-19 14:58:42 -07006971 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08006972 } finally {
6973 Binder.restoreCallingIdentity(identity);
6974 }
6975 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006976
Michele0ea7d782019-03-19 14:58:42 -07006977 @TelephonyManager.IsMultiSimSupportedResult
6978 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08006979 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
6980 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
6981 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07006982 loge("isMultiSimSupportedInternal: requires at least 2 cards");
6983 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006984 }
6985 // Check if the hardware supports multisim functionality. If usage of multisim is not
6986 // supported by the modem, indicate that it is restricted.
6987 PhoneCapability staticCapability =
6988 mPhoneConfigurationManager.getStaticPhoneCapability();
6989 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07006990 loge("isMultiSimSupportedInternal: no static configuration available");
6991 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006992 }
6993 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07006994 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
6995 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006996 }
6997 // Check if support of multiple SIMs is restricted by carrier
6998 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07006999 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007000 }
7001
Michele0ea7d782019-03-19 14:58:42 -07007002 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007003 }
7004
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007005 /**
7006 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007007 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7008 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7009 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007010 * @param numOfSims number of active sims we want to switch to
7011 */
7012 @Override
7013 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007014 if (numOfSims == 1) {
7015 enforceModifyPermission();
7016 } else {
7017 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7018 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
7019 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007020 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08007021
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007022 try {
Michele30b57b22019-03-01 12:01:14 -08007023 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07007024 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08007025 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
7026 return;
7027 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007028 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7029 } finally {
7030 Binder.restoreCallingIdentity(identity);
7031 }
7032 }
7033
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09007034 @Override
7035 public boolean isApplicationOnUicc(int subId, int appType) {
7036 enforceReadPrivilegedPermission("isApplicationOnUicc");
7037 Phone phone = getPhone(subId);
7038 if (phone == null) {
7039 return false;
7040 }
7041 final long identity = Binder.clearCallingIdentity();
7042 try {
7043 UiccCard uiccCard = phone.getUiccCard();
7044 if (uiccCard == null) {
7045 return false;
7046 }
7047 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7048 if (uiccProfile == null) {
7049 return false;
7050 }
7051 if (TelephonyManager.APPTYPE_SIM <= appType
7052 && appType <= TelephonyManager.APPTYPE_ISIM) {
7053 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
7054 }
7055 return false;
7056 } finally {
7057 Binder.restoreCallingIdentity(identity);
7058 }
7059 }
7060
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007061 /**
chen xub4baa772019-04-03 10:23:41 -07007062 * Get whether making changes to modem configurations will trigger reboot.
7063 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007064 */
7065 @Override
chen xub4baa772019-04-03 10:23:41 -07007066 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage) {
7067 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7068 mApp, subId, callingPackage, "doesSwitchMultiSimConfigTriggerReboot")) {
7069 return false;
7070 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007071 final long identity = Binder.clearCallingIdentity();
7072 try {
7073 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
7074 } finally {
7075 Binder.restoreCallingIdentity(identity);
7076 }
7077 }
7078
Nathan Harold29f5f052019-02-15 13:41:57 -08007079 private void updateModemStateMetrics() {
7080 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
7081 // TODO: check the state for each modem if the api is ready.
7082 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
7083 }
7084
Pengquan Meng3889a572019-01-23 11:16:29 -08007085 @Override
7086 public int[] getSlotsMapping() {
7087 enforceReadPrivilegedPermission("getSlotsMapping");
7088
7089 final long identity = Binder.clearCallingIdentity();
7090 try {
7091 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
7092 // All logical slots should have a mapping to a physical slot.
7093 int[] logicalSlotsMapping = new int[phoneCount];
7094 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
7095 for (int i = 0; i < slotInfos.length; i++) {
7096 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
7097 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
7098 }
7099 }
7100 return logicalSlotsMapping;
7101 } finally {
7102 Binder.restoreCallingIdentity(identity);
7103 }
7104 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007105
7106 /**
7107 * Get the IRadio HAL Version
7108 */
7109 @Override
7110 public int getRadioHalVersion() {
7111 Phone phone = getDefaultPhone();
7112 if (phone == null) return -1;
7113 HalVersion hv = phone.getHalVersion();
7114 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7115 return hv.major * 100 + hv.minor;
7116 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007117
7118 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007119 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7120 * corresponding network requests on a subId.
7121 *
7122 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007123 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007124 * 2) APN is un-metered for this subscription, or
7125 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
7126 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on.
7127 *
7128 * @return whether data is allowed for a apn type.
7129 *
7130 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007131 */
7132 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007133 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007134 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Malcolm Chene5ad5792019-04-18 13:51:02 -07007135 mApp, subId, callingPackage, "isDataEnabledForApn")) {
7136 throw new SecurityException("Needs READ_PHONE_STATE for isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007137 }
7138
7139 // Now that all security checks passes, perform the operation as ourselves.
7140 final long identity = Binder.clearCallingIdentity();
7141 try {
7142 Phone phone = getPhone(subId);
7143 if (phone == null) return false;
7144
Jack Yu41407ee2019-05-13 16:54:09 -07007145 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07007146 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7147 } finally {
7148 Binder.restoreCallingIdentity(identity);
7149 }
7150 }
7151
7152 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07007153 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07007154 enforceReadPrivilegedPermission("isApnMetered");
7155
7156 // Now that all security checks passes, perform the operation as ourselves.
7157 final long identity = Binder.clearCallingIdentity();
7158 try {
7159 Phone phone = getPhone(subId);
7160 if (phone == null) return true; // By default return true.
7161
Jack Yu41407ee2019-05-13 16:54:09 -07007162 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007163 } finally {
7164 Binder.restoreCallingIdentity(identity);
7165 }
7166 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007167
7168 @Override
7169 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
7170 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
7171 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
7172 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
7173 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
7174 }
7175 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
7176 Intent intent = new Intent();
7177 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
7178 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7179 // Bring up choose default SMS subscription dialog right now
7180 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
7181 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
7182 mApp.startActivity(intent);
7183 }
chen xud5ca2d52019-05-28 15:20:57 -07007184
7185 @Override
7186 public String getMmsUAProfUrl(int subId) {
7187 //TODO investigate if this API should require proper permission check in R b/133791609
7188 final long identity = Binder.clearCallingIdentity();
7189 try {
7190 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7191 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
7192 } finally {
7193 Binder.restoreCallingIdentity(identity);
7194 }
7195 }
7196
7197 @Override
7198 public String getMmsUserAgent(int subId) {
7199 //TODO investigate if this API should require proper permission check in R b/133791609
7200 final long identity = Binder.clearCallingIdentity();
7201 try {
7202 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7203 .getString(com.android.internal.R.string.config_mms_user_agent);
7204 } finally {
7205 Binder.restoreCallingIdentity(identity);
7206 }
7207 }
Jack Yub07d4972019-05-28 16:12:25 -07007208
7209 @Override
7210 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
7211 enforceModifyPermission();
7212
7213 // Now that all security checks passes, perform the operation as ourselves.
7214 final long identity = Binder.clearCallingIdentity();
7215 try {
7216 Phone phone = getPhone(subId);
7217 if (phone == null) return false;
7218
7219 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
7220 } finally {
7221 Binder.restoreCallingIdentity(identity);
7222 }
7223 }
7224
7225 @Override
7226 public boolean isDataAllowedInVoiceCall(int subId) {
7227 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
7228
7229 // Now that all security checks passes, perform the operation as ourselves.
7230 final long identity = Binder.clearCallingIdentity();
7231 try {
7232 Phone phone = getPhone(subId);
7233 if (phone == null) return false;
7234
7235 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
7236 } finally {
7237 Binder.restoreCallingIdentity(identity);
7238 }
7239 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07007240
7241 /**
7242 * Updates whether conference event pacakge handling is enabled.
7243 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
7244 * otherwise.
7245 */
7246 @Override
7247 public void setCepEnabled(boolean isCepEnabled) {
7248 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
7249
7250 final long identity = Binder.clearCallingIdentity();
7251 try {
7252 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
7253 for (Phone phone : PhoneFactory.getPhones()) {
7254 Phone defaultPhone = phone.getImsPhone();
7255 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7256 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7257 ImsPhoneCallTracker imsPhoneCallTracker =
7258 (ImsPhoneCallTracker) imsPhone.getCallTracker();
7259 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
7260 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
7261 + imsPhone.getMsisdn());
7262 }
7263 }
7264 } finally {
7265 Binder.restoreCallingIdentity(identity);
7266 }
7267 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007268}