blob: 4a75fd0afdaaf260a71c29481e97c7a5c18efdee [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;
Malcolm Chen6ca97372019-07-01 16:28:21 -070048import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070049import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080050import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070051import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070052import android.os.ServiceManager;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070053import android.os.ServiceSpecificException;
Brad Ebingerdac2f002018-04-03 15:17:52 -070054import android.os.ShellCallback;
Pengquan Meng85728fb2018-03-12 16:31:21 -070055import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070056import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070057import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070058import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070059import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080060import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070061import android.provider.Telephony;
Santos Cordon7a1885b2015-02-03 11:15:19 -080062import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080063import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070064import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070065import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080066import android.telephony.CarrierRestrictionRules;
yincheng zhaod698b842019-09-06 17:06:54 -070067import android.telephony.CellIdentity;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070068import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070069import android.telephony.CellInfoGsm;
70import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070071import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070072import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070073import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070074import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080075import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070076import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080077import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070078import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080079import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080080import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070081import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080082import android.telephony.RadioAccessSpecifier;
Tyler Gunn65d45c22017-06-05 11:22:26 -070083import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070084import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080085import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080086import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080087import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070088import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070089import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080090import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080091import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000092import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070093import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070094import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070095import android.telephony.cdma.CdmaCellLocation;
Jack Yub5d8f642018-11-26 11:20:48 -080096import android.telephony.data.ApnSetting;
Jack Yu41407ee2019-05-13 16:54:09 -070097import android.telephony.data.ApnSetting.ApnType;
Jack Yub5d8f642018-11-26 11:20:48 -080098import android.telephony.emergency.EmergencyNumber;
Nathan Harold3ff88932018-08-14 10:19:49 -070099import android.telephony.gsm.GsmCellLocation;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700100import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800101import android.telephony.ims.ProvisioningManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700102import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800103import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700104import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800105import android.telephony.ims.aidl.IImsMmTelFeature;
106import android.telephony.ims.aidl.IImsRcsFeature;
107import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700108import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800109import android.telephony.ims.feature.MmTelFeature;
110import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800111import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700112import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800113import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700114import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800115import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800116import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800117
Andrew Lee312e8172014-10-23 17:01:36 -0700118import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800119import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700120import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700121import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700122import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800123import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700124import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700125import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700126import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800127import com.android.internal.telephony.HalVersion;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700128import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800129import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700130import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800131import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700132import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100133import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700134import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700135import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700136import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700137import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800138import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700139import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700140import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700141import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700142import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700143import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700144import com.android.internal.telephony.ServiceStateTracker;
Makoto Onukida3bf792018-09-18 16:06:29 -0700145import com.android.internal.telephony.SmsApplication;
146import com.android.internal.telephony.SmsApplication.SmsApplicationData;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700147import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700148import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800149import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800150import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700151import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800152import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700153import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800154import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700155import com.android.internal.telephony.imsphone.ImsPhone;
156import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800157import com.android.internal.telephony.metrics.TelephonyMetrics;
Taesu Leef8fbed92019-10-07 18:47:02 +0900158import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700159import com.android.internal.telephony.uicc.IccIoResult;
160import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800161import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700162import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800163import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700164import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800165import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000166import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700167import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800168import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700169import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700170import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800171import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700172import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700173import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800174
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700175import java.io.FileDescriptor;
176import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700177import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800178import java.util.Arrays;
Makoto Onukida3bf792018-09-18 16:06:29 -0700179import java.util.Collection;
sqian11b7a0e2018-12-05 18:48:28 -0800180import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800181import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800182import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100183import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800184import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700185import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800186import java.util.Set;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700187
188/**
189 * Implementation of the ITelephony interface.
190 */
Santos Cordon117fee72014-05-16 17:56:12 -0700191public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700192 private static final String LOG_TAG = "PhoneInterfaceManager";
193 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
194 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800195 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700196
197 // Message codes used with mMainThreadHandler
198 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700199 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
200 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700201 private static final int CMD_OPEN_CHANNEL = 9;
202 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
203 private static final int CMD_CLOSE_CHANNEL = 11;
204 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800205 private static final int CMD_NV_READ_ITEM = 13;
206 private static final int EVENT_NV_READ_ITEM_DONE = 14;
207 private static final int CMD_NV_WRITE_ITEM = 15;
208 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
209 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
210 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700211 private static final int CMD_RESET_MODEM_CONFIG = 19;
212 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800213 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
214 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
215 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
216 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800217 private static final int CMD_SEND_ENVELOPE = 25;
218 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000219 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
220 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700221 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
222 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
223 private static final int CMD_EXCHANGE_SIM_IO = 31;
224 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800225 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
226 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700227 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
228 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700229 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
230 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700231 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
232 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
233 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
234 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700235 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
236 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
237 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
238 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700239 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800240 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
241 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000242 private static final int CMD_SWITCH_SLOTS = 50;
243 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700244 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
245 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
246 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
247 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
248 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
249 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
250 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
251 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700252 private static final int CMD_GET_ALL_CELL_INFO = 60;
253 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
254 private static final int CMD_GET_CELL_LOCATION = 62;
255 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700256 private static final int CMD_MODEM_REBOOT = 64;
257 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700258 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
259 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800260 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
261 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700262 private static final int CMD_GET_MODEM_STATUS = 70;
263 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhaod698b842019-09-06 17:06:54 -0700264 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
265 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700266
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800267 // Parameters of select command.
268 private static final int SELECT_COMMAND = 0xA4;
269 private static final int SELECT_P1 = 0x04;
270 private static final int SELECT_P2 = 0;
271 private static final int SELECT_P3 = 0x10;
272
Pengquan Meng85728fb2018-03-12 16:31:21 -0700273 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
274 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
275 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
276
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700277 /** The singleton instance. */
278 private static PhoneInterfaceManager sInstance;
279
Wink Saville3ab207e2014-11-20 13:07:20 -0800280 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800281 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700282 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800283 private AppOpsManager mAppOps;
284 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800285 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800286 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700287 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700288
Derek Tan97ebb422014-09-05 16:55:38 -0700289 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
290 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800291 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800292 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700293
Michelecea4cf22018-12-21 15:00:11 -0800294 // String to store multi SIM allowed
295 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
296
Derek Tan740e1672017-06-27 14:56:27 -0700297 // The AID of ISD-R.
298 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
299
yinxub1bed742017-04-17 11:45:04 -0700300 private NetworkScanRequestTracker mNetworkScanRequestTracker;
301
David Kelly5e06a7f2018-03-12 14:10:59 +0000302 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
303 private static final int MANUFACTURER_CODE_LENGTH = 8;
304
Derek Tan89e89d42014-07-08 17:00:10 -0700305 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700306 * A request object to use for transmitting data to an ICC.
307 */
308 private static final class IccAPDUArgument {
309 public int channel, cla, command, p1, p2, p3;
310 public String data;
311
312 public IccAPDUArgument(int channel, int cla, int command,
313 int p1, int p2, int p3, String data) {
314 this.channel = channel;
315 this.cla = cla;
316 this.command = command;
317 this.p1 = p1;
318 this.p2 = p2;
319 this.p3 = p3;
320 this.data = data;
321 }
322 }
323
324 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700325 * A request object to use for transmitting data to an ICC.
326 */
327 private static final class ManualNetworkSelectionArgument {
328 public OperatorInfo operatorInfo;
329 public boolean persistSelection;
330
331 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
332 this.operatorInfo = operatorInfo;
333 this.persistSelection = persistSelection;
334 }
335 }
336
337 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700338 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
339 * request after sending. The main thread will notify the request when it is complete.
340 */
341 private static final class MainThreadRequest {
342 /** The argument to use for the request */
343 public Object argument;
344 /** The result of the request that is run on the main thread */
345 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800346 // The subscriber id that this request applies to. Defaults to
347 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
348 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700349
Nathan Harold92bed182018-10-12 18:16:49 -0700350 // In cases where subId is unavailable, the caller needs to specify the phone.
351 public Phone phone;
352
vagdeviaf9a5b92018-08-15 16:01:53 -0700353 public WorkSource workSource;
354
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700355 public MainThreadRequest(Object argument) {
356 this.argument = argument;
357 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800358
Nathan Harold92bed182018-10-12 18:16:49 -0700359 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
360 this.argument = argument;
361 if (phone != null) {
362 this.phone = phone;
363 }
364 this.workSource = workSource;
365 }
366
vagdeviaf9a5b92018-08-15 16:01:53 -0700367 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800368 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800369 if (subId != null) {
370 this.subId = subId;
371 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700372 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800373 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700374 }
375
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800376 private static final class IncomingThirdPartyCallArgs {
377 public final ComponentName component;
378 public final String callId;
379 public final String callerDisplayName;
380
381 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
382 String callerDisplayName) {
383 this.component = component;
384 this.callId = callId;
385 this.callerDisplayName = callerDisplayName;
386 }
387 }
388
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700389 /**
390 * A handler that processes messages on the main thread in the phone process. Since many
391 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
392 * inbound binder threads to the main thread in the phone process. The Binder thread
393 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
394 * on, which will be notified when the operation completes and will contain the result of the
395 * request.
396 *
397 * <p>If a MainThreadRequest object is provided in the msg.obj field,
398 * note that request.result must be set to something non-null for the calling thread to
399 * unblock.
400 */
401 private final class MainThreadHandler extends Handler {
402 @Override
403 public void handleMessage(Message msg) {
404 MainThreadRequest request;
405 Message onCompleted;
406 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800407 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700408 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800409 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700410
411 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700412 case CMD_HANDLE_USSD_REQUEST: {
413 request = (MainThreadRequest) msg.obj;
414 final Phone phone = getPhoneFromRequest(request);
415 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
416 String ussdRequest = ussdObject.first;
417 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700418
Pengquan Menga1bb6272018-09-06 09:59:22 -0700419 if (!isUssdApiAllowed(request.subId)) {
420 // Carrier does not support use of this API, return failure.
421 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
422 UssdResponse response = new UssdResponse(ussdRequest, null);
423 Bundle returnData = new Bundle();
424 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
425 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700426
Pengquan Menga1bb6272018-09-06 09:59:22 -0700427 request.result = true;
428 notifyRequester(request);
429 return;
430 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700431
Pengquan Menga1bb6272018-09-06 09:59:22 -0700432 try {
433 request.result = phone != null
434 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
435 } catch (CallStateException cse) {
436 request.result = false;
437 }
438 // Wake up the requesting thread
439 notifyRequester(request);
440 break;
pkanwar32d516d2016-10-14 19:37:38 -0700441 }
442
Yorke Lee716f67e2015-06-17 15:39:16 -0700443 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700444 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700445 final Phone phone = getPhoneFromRequest(request);
446 request.result = phone != null ?
447 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
448 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700449 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700450 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700451 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700452 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700453
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700454 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700455 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700456 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800457 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700458 if (uiccCard == null) {
459 loge("iccTransmitApduLogicalChannel: No UICC");
460 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700461 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700462 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700463 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
464 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700465 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700466 iccArgument.channel, iccArgument.cla, iccArgument.command,
467 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700468 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700469 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700470 break;
471
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700472 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700473 ar = (AsyncResult) msg.obj;
474 request = (MainThreadRequest) ar.userObj;
475 if (ar.exception == null && ar.result != null) {
476 request.result = ar.result;
477 } else {
478 request.result = new IccIoResult(0x6F, 0, (byte[])null);
479 if (ar.result == null) {
480 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800481 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700482 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800483 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700484 } else {
485 loge("iccTransmitApduLogicalChannel: Unknown exception");
486 }
487 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700488 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700489 break;
490
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700491 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
492 request = (MainThreadRequest) msg.obj;
493 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800494 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700495 if (uiccCard == null) {
496 loge("iccTransmitApduBasicChannel: No UICC");
497 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700498 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700499 } else {
500 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
501 request);
502 uiccCard.iccTransmitApduBasicChannel(
503 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
504 iccArgument.p3, iccArgument.data, onCompleted);
505 }
506 break;
507
508 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
509 ar = (AsyncResult) msg.obj;
510 request = (MainThreadRequest) ar.userObj;
511 if (ar.exception == null && ar.result != null) {
512 request.result = ar.result;
513 } else {
514 request.result = new IccIoResult(0x6F, 0, (byte[])null);
515 if (ar.result == null) {
516 loge("iccTransmitApduBasicChannel: Empty response");
517 } else if (ar.exception instanceof CommandException) {
518 loge("iccTransmitApduBasicChannel: CommandException: " +
519 ar.exception);
520 } else {
521 loge("iccTransmitApduBasicChannel: Unknown exception");
522 }
523 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700524 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700525 break;
526
527 case CMD_EXCHANGE_SIM_IO:
528 request = (MainThreadRequest) msg.obj;
529 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800530 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700531 if (uiccCard == null) {
532 loge("iccExchangeSimIO: No UICC");
533 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700534 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700535 } else {
536 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
537 request);
538 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
539 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
540 iccArgument.data, onCompleted);
541 }
542 break;
543
544 case EVENT_EXCHANGE_SIM_IO_DONE:
545 ar = (AsyncResult) msg.obj;
546 request = (MainThreadRequest) ar.userObj;
547 if (ar.exception == null && ar.result != null) {
548 request.result = ar.result;
549 } else {
550 request.result = new IccIoResult(0x6f, 0, (byte[])null);
551 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700552 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700553 break;
554
Derek Tan4d5e5c12014-02-04 11:54:58 -0800555 case CMD_SEND_ENVELOPE:
556 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800557 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700558 if (uiccCard == null) {
559 loge("sendEnvelopeWithStatus: No UICC");
560 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700561 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700562 } else {
563 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
564 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
565 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800566 break;
567
568 case EVENT_SEND_ENVELOPE_DONE:
569 ar = (AsyncResult) msg.obj;
570 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700571 if (ar.exception == null && ar.result != null) {
572 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800573 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700574 request.result = new IccIoResult(0x6F, 0, (byte[])null);
575 if (ar.result == null) {
576 loge("sendEnvelopeWithStatus: Empty response");
577 } else if (ar.exception instanceof CommandException) {
578 loge("sendEnvelopeWithStatus: CommandException: " +
579 ar.exception);
580 } else {
581 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
582 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800583 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700584 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800585 break;
586
Shishir Agrawal566b7612013-10-28 14:41:00 -0700587 case CMD_OPEN_CHANNEL:
588 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800589 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800590 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700591 if (uiccCard == null) {
592 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800593 request.result = new IccOpenLogicalChannelResponse(-1,
594 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700595 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700596 } else {
597 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800598 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
599 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700600 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700601 break;
602
603 case EVENT_OPEN_CHANNEL_DONE:
604 ar = (AsyncResult) msg.obj;
605 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700606 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700607 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700608 int[] result = (int[]) ar.result;
609 int channelId = result[0];
610 byte[] selectResponse = null;
611 if (result.length > 1) {
612 selectResponse = new byte[result.length - 1];
613 for (int i = 1; i < result.length; ++i) {
614 selectResponse[i - 1] = (byte) result[i];
615 }
616 }
617 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700618 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700619 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700620 if (ar.result == null) {
621 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700622 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700623 if (ar.exception != null) {
624 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
625 }
626
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700627 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700628 if (ar.exception instanceof CommandException) {
629 CommandException.Error error =
630 ((CommandException) (ar.exception)).getCommandError();
631 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700632 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700633 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700634 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700635 }
636 }
637 openChannelResp = new IccOpenLogicalChannelResponse(
638 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700639 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700640 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700641 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700642 break;
643
644 case CMD_CLOSE_CHANNEL:
645 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800646 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700647 if (uiccCard == null) {
648 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900649 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700650 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700651 } else {
652 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
653 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
654 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700655 break;
656
657 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800658 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
659 break;
660
661 case CMD_NV_READ_ITEM:
662 request = (MainThreadRequest) msg.obj;
663 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800664 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
665 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800666 break;
667
668 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700669 ar = (AsyncResult) msg.obj;
670 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800671 if (ar.exception == null && ar.result != null) {
672 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700673 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800674 request.result = "";
675 if (ar.result == null) {
676 loge("nvReadItem: Empty response");
677 } else if (ar.exception instanceof CommandException) {
678 loge("nvReadItem: CommandException: " +
679 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700680 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800681 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700682 }
683 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700684 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700685 break;
686
Jake Hambye994d462014-02-03 13:10:13 -0800687 case CMD_NV_WRITE_ITEM:
688 request = (MainThreadRequest) msg.obj;
689 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
690 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800691 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700692 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800693 break;
694
695 case EVENT_NV_WRITE_ITEM_DONE:
696 handleNullReturnEvent(msg, "nvWriteItem");
697 break;
698
699 case CMD_NV_WRITE_CDMA_PRL:
700 request = (MainThreadRequest) msg.obj;
701 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800702 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800703 break;
704
705 case EVENT_NV_WRITE_CDMA_PRL_DONE:
706 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
707 break;
708
chen xu6dac5ab2018-10-26 17:39:23 -0700709 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800710 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700711 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800712 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800713 break;
714
chen xu6dac5ab2018-10-26 17:39:23 -0700715 case EVENT_RESET_MODEM_CONFIG_DONE:
716 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800717 break;
718
Jake Hamby7c27be32014-03-03 13:25:59 -0800719 case CMD_GET_PREFERRED_NETWORK_TYPE:
720 request = (MainThreadRequest) msg.obj;
721 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700722 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800723 break;
724
725 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
726 ar = (AsyncResult) msg.obj;
727 request = (MainThreadRequest) ar.userObj;
728 if (ar.exception == null && ar.result != null) {
729 request.result = ar.result; // Integer
730 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800731 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800732 if (ar.result == null) {
733 loge("getPreferredNetworkType: Empty response");
734 } else if (ar.exception instanceof CommandException) {
735 loge("getPreferredNetworkType: CommandException: " +
736 ar.exception);
737 } else {
738 loge("getPreferredNetworkType: Unknown exception");
739 }
740 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700741 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800742 break;
743
744 case CMD_SET_PREFERRED_NETWORK_TYPE:
745 request = (MainThreadRequest) msg.obj;
746 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
747 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700748 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800749 break;
750
751 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
752 handleNullReturnEvent(msg, "setPreferredNetworkType");
753 break;
754
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000755 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
756 request = (MainThreadRequest)msg.obj;
757 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800758 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000759 break;
760
761 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
762 ar = (AsyncResult)msg.obj;
763 request = (MainThreadRequest)ar.userObj;
764 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700765 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000766 break;
767
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800768 case CMD_SET_VOICEMAIL_NUMBER:
769 request = (MainThreadRequest) msg.obj;
770 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
771 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800772 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
773 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800774 break;
775
776 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
777 handleNullReturnEvent(msg, "setVoicemailNumber");
778 break;
779
Stuart Scott54788802015-03-30 13:18:01 -0700780 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
781 request = (MainThreadRequest) msg.obj;
782 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
783 request);
784 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
785 break;
786
787 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
788 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
789 break;
790
Shishir Agrawal302c8692015-06-19 13:49:39 -0700791 case CMD_PERFORM_NETWORK_SCAN:
792 request = (MainThreadRequest) msg.obj;
793 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
794 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
795 break;
796
797 case EVENT_PERFORM_NETWORK_SCAN_DONE:
798 ar = (AsyncResult) msg.obj;
799 request = (MainThreadRequest) ar.userObj;
800 CellNetworkScanResult cellScanResult;
801 if (ar.exception == null && ar.result != null) {
802 cellScanResult = new CellNetworkScanResult(
803 CellNetworkScanResult.STATUS_SUCCESS,
804 (List<OperatorInfo>) ar.result);
805 } else {
806 if (ar.result == null) {
807 loge("getCellNetworkScanResults: Empty response");
808 }
809 if (ar.exception != null) {
810 loge("getCellNetworkScanResults: Exception: " + ar.exception);
811 }
812 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
813 if (ar.exception instanceof CommandException) {
814 CommandException.Error error =
815 ((CommandException) (ar.exception)).getCommandError();
816 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
817 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
818 } else if (error == CommandException.Error.GENERIC_FAILURE) {
819 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
820 }
821 }
822 cellScanResult = new CellNetworkScanResult(errorCode, null);
823 }
824 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700825 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700826 break;
827
828 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
829 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700830 ManualNetworkSelectionArgument selArg =
831 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700832 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
833 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700834 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
835 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700836 break;
837
838 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700839 ar = (AsyncResult) msg.obj;
840 request = (MainThreadRequest) ar.userObj;
841 if (ar.exception == null) {
842 request.result = true;
843 } else {
844 request.result = false;
845 loge("setNetworkSelectionModeManual " + ar.exception);
846 }
847 notifyRequester(request);
848 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700849 break;
850
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700851 case CMD_GET_MODEM_ACTIVITY_INFO:
852 request = (MainThreadRequest) msg.obj;
853 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -0700854 if (defaultPhone != null) {
855 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
856 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700857 break;
858
859 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
860 ar = (AsyncResult) msg.obj;
861 request = (MainThreadRequest) ar.userObj;
862 if (ar.exception == null && ar.result != null) {
863 request.result = ar.result;
864 } else {
865 if (ar.result == null) {
866 loge("queryModemActivityInfo: Empty response");
867 } else if (ar.exception instanceof CommandException) {
868 loge("queryModemActivityInfo: CommandException: " +
869 ar.exception);
870 } else {
871 loge("queryModemActivityInfo: Unknown exception");
872 }
873 }
Amit Mahajand4766222016-01-28 15:28:28 -0800874 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
875 if (request.result == null) {
876 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
877 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700878 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700879 break;
880
Meng Wang1a7c35a2016-05-05 20:56:15 -0700881 case CMD_SET_ALLOWED_CARRIERS:
882 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -0800883 CarrierRestrictionRules argument =
884 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700885 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -0800886 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700887 break;
888
889 case EVENT_SET_ALLOWED_CARRIERS_DONE:
890 ar = (AsyncResult) msg.obj;
891 request = (MainThreadRequest) ar.userObj;
892 if (ar.exception == null && ar.result != null) {
893 request.result = ar.result;
894 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800895 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
896 if (ar.exception instanceof CommandException) {
897 loge("setAllowedCarriers: CommandException: " + ar.exception);
898 CommandException.Error error =
899 ((CommandException) (ar.exception)).getCommandError();
900 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
901 request.result =
902 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
903 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700904 } else {
905 loge("setAllowedCarriers: Unknown exception");
906 }
907 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700908 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700909 break;
910
911 case CMD_GET_ALLOWED_CARRIERS:
912 request = (MainThreadRequest) msg.obj;
913 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800914 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700915 break;
916
917 case EVENT_GET_ALLOWED_CARRIERS_DONE:
918 ar = (AsyncResult) msg.obj;
919 request = (MainThreadRequest) ar.userObj;
920 if (ar.exception == null && ar.result != null) {
921 request.result = ar.result;
922 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800923 request.result = new IllegalStateException(
924 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700925 if (ar.result == null) {
926 loge("getAllowedCarriers: Empty response");
927 } else if (ar.exception instanceof CommandException) {
928 loge("getAllowedCarriers: CommandException: " +
929 ar.exception);
930 } else {
931 loge("getAllowedCarriers: Unknown exception");
932 }
933 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700934 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700935 break;
936
Nathan Haroldb3014052017-01-25 15:57:32 -0800937 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
938 ar = (AsyncResult) msg.obj;
939 request = (MainThreadRequest) ar.userObj;
940 if (ar.exception == null && ar.result != null) {
941 request.result = ar.result;
942 } else {
943 request.result = new IllegalArgumentException(
944 "Failed to retrieve Forbidden Plmns");
945 if (ar.result == null) {
946 loge("getForbiddenPlmns: Empty response");
947 } else {
948 loge("getForbiddenPlmns: Unknown exception");
949 }
950 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700951 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800952 break;
953
954 case CMD_GET_FORBIDDEN_PLMNS:
955 request = (MainThreadRequest) msg.obj;
956 uiccCard = getUiccCardFromRequest(request);
957 if (uiccCard == null) {
958 loge("getForbiddenPlmns() UiccCard is null");
959 request.result = new IllegalArgumentException(
960 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700961 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800962 break;
963 }
964 Integer appType = (Integer) request.argument;
965 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
966 if (uiccApp == null) {
967 loge("getForbiddenPlmns() no app with specified type -- "
968 + appType);
969 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700970 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800971 break;
972 } else {
973 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
974 + " specified type -- " + appType);
975 }
976 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
977 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
978 onCompleted);
979 break;
980
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000981 case CMD_SWITCH_SLOTS:
982 request = (MainThreadRequest) msg.obj;
983 int[] physicalSlots = (int[]) request.argument;
984 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
985 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
986 break;
987
988 case EVENT_SWITCH_SLOTS_DONE:
989 ar = (AsyncResult) msg.obj;
990 request = (MainThreadRequest) ar.userObj;
991 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700992 notifyRequester(request);
993 break;
994 case CMD_GET_NETWORK_SELECTION_MODE:
995 request = (MainThreadRequest) msg.obj;
996 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
997 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
998 break;
999
1000 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1001 ar = (AsyncResult) msg.obj;
1002 request = (MainThreadRequest) ar.userObj;
1003 if (ar.exception != null) {
1004 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1005 } else {
1006 int mode = ((int[]) ar.result)[0];
1007 if (mode == 0) {
1008 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1009 } else {
1010 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1011 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001012 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001013 notifyRequester(request);
1014 break;
1015 case CMD_GET_CDMA_ROAMING_MODE:
1016 request = (MainThreadRequest) msg.obj;
1017 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1018 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1019 break;
1020 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1021 ar = (AsyncResult) msg.obj;
1022 request = (MainThreadRequest) ar.userObj;
1023 if (ar.exception != null) {
1024 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1025 } else {
1026 request.result = ((int[]) ar.result)[0];
1027 }
1028 notifyRequester(request);
1029 break;
1030 case CMD_SET_CDMA_ROAMING_MODE:
1031 request = (MainThreadRequest) msg.obj;
1032 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1033 int mode = (int) request.argument;
1034 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1035 break;
1036 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1037 ar = (AsyncResult) msg.obj;
1038 request = (MainThreadRequest) ar.userObj;
1039 request.result = ar.exception == null;
1040 notifyRequester(request);
1041 break;
1042 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1043 request = (MainThreadRequest) msg.obj;
1044 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1045 int subscriptionMode = (int) request.argument;
1046 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1047 break;
1048 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1049 ar = (AsyncResult) msg.obj;
1050 request = (MainThreadRequest) ar.userObj;
1051 request.result = ar.exception == null;
1052 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001053 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001054 case CMD_GET_ALL_CELL_INFO:
1055 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001056 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001057 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001058 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001059 case EVENT_GET_ALL_CELL_INFO_DONE:
1060 ar = (AsyncResult) msg.obj;
1061 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001062 // If a timeout occurs, the response will be null
1063 request.result = (ar.exception == null && ar.result != null)
1064 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001065 synchronized (request) {
1066 request.notifyAll();
1067 }
1068 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001069 case CMD_REQUEST_CELL_INFO_UPDATE:
1070 request = (MainThreadRequest) msg.obj;
1071 request.phone.requestCellInfoUpdate(request.workSource,
1072 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1073 break;
1074 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1075 ar = (AsyncResult) msg.obj;
1076 request = (MainThreadRequest) ar.userObj;
1077 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1078 try {
1079 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001080 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Nathan Harolde82c4b82018-12-18 19:40:37 -08001081 cb.onError(TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1082 new android.os.ParcelableException(ar.exception));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001083 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001084 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Nathan Harolde82c4b82018-12-18 19:40:37 -08001085 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001086 } else {
1087 // use the result as returned
1088 cb.onCellInfo((List<CellInfo>) ar.result);
1089 }
1090 } catch (RemoteException re) {
1091 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1092 }
1093 break;
1094 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001095 request = (MainThreadRequest) msg.obj;
1096 WorkSource ws = (WorkSource) request.argument;
1097 Phone phone = getPhoneFromRequest(request);
1098 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1099 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001100 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001101 ar = (AsyncResult) msg.obj;
1102 request = (MainThreadRequest) ar.userObj;
1103 if (ar.exception == null) {
1104 request.result = ar.result;
1105 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001106 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001107 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1108 ? new CdmaCellLocation() : new GsmCellLocation();
1109 }
1110
1111 synchronized (request) {
1112 request.notifyAll();
1113 }
1114 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001115 case CMD_MODEM_REBOOT:
1116 request = (MainThreadRequest) msg.obj;
1117 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001118 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001119 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001120 case EVENT_CMD_MODEM_REBOOT_DONE:
1121 handleNullReturnEvent(msg, "rebootModem");
1122 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001123 case CMD_REQUEST_ENABLE_MODEM:
1124 request = (MainThreadRequest) msg.obj;
1125 boolean enable = (boolean) request.argument;
1126 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001127 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001128 PhoneConfigurationManager.getInstance()
1129 .enablePhone(request.phone, enable, onCompleted);
1130 break;
1131 case EVENT_ENABLE_MODEM_DONE:
1132 ar = (AsyncResult) msg.obj;
1133 request = (MainThreadRequest) ar.userObj;
1134 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001135 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001136 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001137 if ((boolean) request.result) {
1138 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1139 updateModemStateMetrics();
1140 } else {
1141 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1142 + ar.exception);
1143 }
1144 notifyRequester(request);
1145 break;
1146 case CMD_GET_MODEM_STATUS:
1147 request = (MainThreadRequest) msg.obj;
1148 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1149 PhoneConfigurationManager.getInstance()
1150 .getPhoneStatusFromModem(request.phone, onCompleted);
1151 break;
1152 case EVENT_GET_MODEM_STATUS_DONE:
1153 ar = (AsyncResult) msg.obj;
1154 request = (MainThreadRequest) ar.userObj;
1155 int id = request.phone.getPhoneId();
1156 if (ar.exception == null && ar.result != null) {
1157 request.result = ar.result;
1158 //update the cache as modem status has changed
1159 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1160 (boolean) request.result);
1161 } else {
1162 // Return true if modem status cannot be retrieved. For most cases,
1163 // modem status is on. And for older version modems, GET_MODEM_STATUS
1164 // and disable modem are not supported. Modem is always on.
1165 // TODO: this should be fixed in R to support a third
1166 // status UNKNOWN b/131631629
1167 request.result = true;
1168 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1169 + ar.exception);
1170 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001171 notifyRequester(request);
1172 break;
yincheng zhaod698b842019-09-06 17:06:54 -07001173 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1174 ar = (AsyncResult) msg.obj;
1175 request = (MainThreadRequest) ar.userObj;
1176 if (ar.exception == null && ar.result != null) {
1177 request.result = ar.result;
1178 } else {
1179 request.result = -1;
1180 loge("Failed to set Forbidden Plmns");
1181 if (ar.result == null) {
1182 loge("setForbidenPlmns: Empty response");
1183 } else if (ar.exception != null) {
1184 loge("setForbiddenPlmns: Exception: " + ar.exception);
1185 request.result = -1;
1186 } else {
1187 loge("setForbiddenPlmns: Unknown exception");
1188 }
1189 }
1190 notifyRequester(request);
1191 break;
1192 case CMD_SET_FORBIDDEN_PLMNS:
1193 request = (MainThreadRequest) msg.obj;
1194 uiccCard = getUiccCardFromRequest(request);
1195 if (uiccCard == null) {
1196 loge("setForbiddenPlmns: UiccCard is null");
1197 request.result = -1;
1198 notifyRequester(request);
1199 break;
1200 }
1201 Pair<Integer, List<String>> setFplmnsArgs =
1202 (Pair<Integer, List<String>>) request.argument;
1203 appType = setFplmnsArgs.first;
1204 List<String> fplmns = setFplmnsArgs.second;
1205 uiccApp = uiccCard.getApplicationByType(appType);
1206 if (uiccApp == null) {
1207 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1208 request.result = -1;
1209 loge("Failed to get UICC App");
1210 notifyRequester(request);
1211 } else {
1212 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1213 ((SIMRecords) uiccApp.getIccRecords())
1214 .setForbiddenPlmns(onCompleted, fplmns);
1215 }
1216 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001217 default:
1218 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1219 break;
1220 }
1221 }
Jake Hambye994d462014-02-03 13:10:13 -08001222
Pengquan Menga1bb6272018-09-06 09:59:22 -07001223 private void notifyRequester(MainThreadRequest request) {
1224 synchronized (request) {
1225 request.notifyAll();
1226 }
1227 }
1228
Jake Hambye994d462014-02-03 13:10:13 -08001229 private void handleNullReturnEvent(Message msg, String command) {
1230 AsyncResult ar = (AsyncResult) msg.obj;
1231 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1232 if (ar.exception == null) {
1233 request.result = true;
1234 } else {
1235 request.result = false;
1236 if (ar.exception instanceof CommandException) {
1237 loge(command + ": CommandException: " + ar.exception);
1238 } else {
1239 loge(command + ": Unknown exception");
1240 }
1241 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001242 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001243 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001244 }
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(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001252 return sendRequest(
1253 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001254 }
1255
1256 /**
1257 * Posts the specified command to be executed on the main thread,
1258 * waits for the request to complete, and returns the result.
1259 * @see #sendRequestAsync
1260 */
1261 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1262 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001263 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001264 }
1265
1266 /**
1267 * Posts the specified command to be executed on the main thread,
1268 * waits for the request to complete, and returns the result.
1269 * @see #sendRequestAsync
1270 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001271 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001272 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001273 }
1274
1275 /**
1276 * Posts the specified command to be executed on the main thread,
1277 * waits for the request to complete, and returns the result.
1278 * @see #sendRequestAsync
1279 */
Nathan Harold92bed182018-10-12 18:16:49 -07001280 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1281 return sendRequest(command, argument, subId, null, workSource);
1282 }
1283
1284 /**
1285 * Posts the specified command to be executed on the main thread,
1286 * waits for the request to complete, and returns the result.
1287 * @see #sendRequestAsync
1288 */
1289 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1290 return sendRequest(
1291 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1292 }
1293
1294 /**
1295 * Posts the specified command to be executed on the main thread,
1296 * waits for the request to complete, and returns the result.
1297 * @see #sendRequestAsync
1298 */
1299 private Object sendRequest(
1300 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001301 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1302 throw new RuntimeException("This method will deadlock if called from the main thread.");
1303 }
1304
Nathan Harold92bed182018-10-12 18:16:49 -07001305 MainThreadRequest request = null;
1306 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1307 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1308 } else if (phone != null) {
1309 request = new MainThreadRequest(argument, phone, workSource);
1310 } else {
1311 request = new MainThreadRequest(argument, subId, workSource);
1312 }
1313
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001314 Message msg = mMainThreadHandler.obtainMessage(command, request);
1315 msg.sendToTarget();
1316
1317 // Wait for the request to complete
1318 synchronized (request) {
1319 while (request.result == null) {
1320 try {
1321 request.wait();
1322 } catch (InterruptedException e) {
1323 // Do nothing, go back and wait until the request is complete
1324 }
1325 }
1326 }
1327 return request.result;
1328 }
1329
1330 /**
1331 * Asynchronous ("fire and forget") version of sendRequest():
1332 * Posts the specified command to be executed on the main thread, and
1333 * returns immediately.
1334 * @see #sendRequest
1335 */
1336 private void sendRequestAsync(int command) {
1337 mMainThreadHandler.sendEmptyMessage(command);
1338 }
1339
1340 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001341 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001342 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001343 */
1344 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001345 sendRequestAsync(command, argument, null, null);
1346 }
1347
1348 /**
1349 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1350 * @see {@link #sendRequest(int,Object)}
1351 */
1352 private void sendRequestAsync(
1353 int command, Object argument, Phone phone, WorkSource workSource) {
1354 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001355 Message msg = mMainThreadHandler.obtainMessage(command, request);
1356 msg.sendToTarget();
1357 }
1358
1359 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001360 * Initialize the singleton PhoneInterfaceManager instance.
1361 * This is only done once, at startup, from PhoneApp.onCreate().
1362 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001363 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001364 synchronized (PhoneInterfaceManager.class) {
1365 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001366 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001367 } else {
1368 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1369 }
1370 return sInstance;
1371 }
1372 }
1373
1374 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001375 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001376 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001377 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001378 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001379 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1380 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001381 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001382 mTelephonySharedPreferences =
1383 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001384 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001385 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001386
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001387 publish();
1388 }
1389
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001390 private Phone getDefaultPhone() {
1391 Phone thePhone = getPhone(getDefaultSubscription());
1392 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1393 }
1394
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001395 private void publish() {
1396 if (DBG) log("publish: " + this);
1397
1398 ServiceManager.addService("phone", this);
1399 }
1400
Stuart Scott584921c2015-01-15 17:10:34 -08001401 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001402 if (request.phone != null) {
1403 return request.phone;
1404 } else {
1405 return getPhoneFromSubId(request.subId);
1406 }
1407 }
1408
1409 private Phone getPhoneFromSubId(int subId) {
1410 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1411 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001412 }
1413
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001414 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1415 Phone phone = getPhoneFromRequest(request);
1416 return phone == null ? null :
1417 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1418 }
1419
Wink Saville36469e72014-06-11 15:17:00 -07001420 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001421 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001422 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001423 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001424
1425 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001426 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001427 }
1428
Wink Savilleb564aae2014-10-23 10:18:09 -07001429 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001430 if (DBG) log("dial: " + number);
1431 // No permission check needed here: This is just a wrapper around the
1432 // ACTION_DIAL intent, which is available to any app since it puts up
1433 // the UI before it does anything.
1434
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001435 final long identity = Binder.clearCallingIdentity();
1436 try {
1437 String url = createTelUrl(number);
1438 if (url == null) {
1439 return;
1440 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001441
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001442 // PENDING: should we just silently fail if phone is offhook or ringing?
1443 PhoneConstants.State state = mCM.getState(subId);
1444 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1445 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1446 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1447 mApp.startActivity(intent);
1448 }
1449 } finally {
1450 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001451 }
1452 }
1453
1454 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001455 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001456 }
1457
Wink Savilleb564aae2014-10-23 10:18:09 -07001458 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001459 if (DBG) log("call: " + number);
1460
1461 // This is just a wrapper around the ACTION_CALL intent, but we still
1462 // need to do a permission check since we're calling startActivity()
1463 // from the context of the phone app.
1464 enforceCallPermission();
1465
Jordan Liu1617b712019-07-10 15:06:26 -07001466 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001467 != AppOpsManager.MODE_ALLOWED) {
1468 return;
1469 }
1470
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001471 final long identity = Binder.clearCallingIdentity();
1472 try {
1473 String url = createTelUrl(number);
1474 if (url == null) {
1475 return;
1476 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001477
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001478 boolean isValid = false;
1479 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1480 if (slist != null) {
1481 for (SubscriptionInfo subInfoRecord : slist) {
1482 if (subInfoRecord.getSubscriptionId() == subId) {
1483 isValid = true;
1484 break;
1485 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001486 }
Wink Saville08874612014-08-31 19:19:58 -07001487 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001488 if (!isValid) {
1489 return;
1490 }
Wink Saville08874612014-08-31 19:19:58 -07001491
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001492 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1493 intent.putExtra(SUBSCRIPTION_KEY, subId);
1494 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1495 mApp.startActivity(intent);
1496 } finally {
1497 Binder.restoreCallingIdentity(identity);
1498 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001499 }
1500
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001501 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001502 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001503 }
1504
Wink Savilleb564aae2014-10-23 10:18:09 -07001505 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001506 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001507 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1508 }
1509
1510 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001511 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001512 }
1513
Wink Savilleb564aae2014-10-23 10:18:09 -07001514 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001515 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001516 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1517 }
1518
1519 /** {@hide} */
1520 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001521 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001522 }
1523
Wink Savilleb564aae2014-10-23 10:18:09 -07001524 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001525 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001526
1527 final long identity = Binder.clearCallingIdentity();
1528 try {
1529 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1530 checkSimPin.start();
1531 return checkSimPin.unlockSim(null, pin);
1532 } finally {
1533 Binder.restoreCallingIdentity(identity);
1534 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001535 }
1536
Wink Saville9de0f752013-10-22 19:04:03 -07001537 /** {@hide} */
1538 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001539 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001540 }
1541
Wink Savilleb564aae2014-10-23 10:18:09 -07001542 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001543 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001544
1545 final long identity = Binder.clearCallingIdentity();
1546 try {
1547 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1548 checkSimPuk.start();
1549 return checkSimPuk.unlockSim(puk, pin);
1550 } finally {
1551 Binder.restoreCallingIdentity(identity);
1552 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001553 }
1554
1555 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001556 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001557 * a synchronous one.
1558 */
1559 private static class UnlockSim extends Thread {
1560
1561 private final IccCard mSimCard;
1562
1563 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001564 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1565 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001566
1567 // For replies from SimCard interface
1568 private Handler mHandler;
1569
1570 // For async handler to identify request type
1571 private static final int SUPPLY_PIN_COMPLETE = 100;
1572
1573 public UnlockSim(IccCard simCard) {
1574 mSimCard = simCard;
1575 }
1576
1577 @Override
1578 public void run() {
1579 Looper.prepare();
1580 synchronized (UnlockSim.this) {
1581 mHandler = new Handler() {
1582 @Override
1583 public void handleMessage(Message msg) {
1584 AsyncResult ar = (AsyncResult) msg.obj;
1585 switch (msg.what) {
1586 case SUPPLY_PIN_COMPLETE:
1587 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1588 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001589 mRetryCount = msg.arg1;
1590 if (ar.exception != null) {
1591 if (ar.exception instanceof CommandException &&
1592 ((CommandException)(ar.exception)).getCommandError()
1593 == CommandException.Error.PASSWORD_INCORRECT) {
1594 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1595 } else {
1596 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1597 }
1598 } else {
1599 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1600 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001601 mDone = true;
1602 UnlockSim.this.notifyAll();
1603 }
1604 break;
1605 }
1606 }
1607 };
1608 UnlockSim.this.notifyAll();
1609 }
1610 Looper.loop();
1611 }
1612
1613 /*
1614 * Use PIN or PUK to unlock SIM card
1615 *
1616 * If PUK is null, unlock SIM card with PIN
1617 *
1618 * If PUK is not null, unlock SIM card with PUK and set PIN code
1619 */
Wink Saville9de0f752013-10-22 19:04:03 -07001620 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001621
1622 while (mHandler == null) {
1623 try {
1624 wait();
1625 } catch (InterruptedException e) {
1626 Thread.currentThread().interrupt();
1627 }
1628 }
1629 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1630
1631 if (puk == null) {
1632 mSimCard.supplyPin(pin, callback);
1633 } else {
1634 mSimCard.supplyPuk(puk, pin, callback);
1635 }
1636
1637 while (!mDone) {
1638 try {
1639 Log.d(LOG_TAG, "wait for done");
1640 wait();
1641 } catch (InterruptedException e) {
1642 // Restore the interrupted status
1643 Thread.currentThread().interrupt();
1644 }
1645 }
1646 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001647 int[] resultArray = new int[2];
1648 resultArray[0] = mResult;
1649 resultArray[1] = mRetryCount;
1650 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001651 }
1652 }
1653
1654 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001655 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001656
1657 }
1658
Wink Savilleb564aae2014-10-23 10:18:09 -07001659 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001660 // No permission check needed here: this call is harmless, and it's
1661 // needed for the ServiceState.requestStateUpdate() call (which is
1662 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001663 final long identity = Binder.clearCallingIdentity();
1664 try {
1665 final Phone phone = getPhone(subId);
1666 if (phone != null) {
1667 phone.updateServiceLocation();
1668 }
1669 } finally {
1670 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001671 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001672 }
1673
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001674 @Override
1675 public boolean isRadioOn(String callingPackage) {
1676 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001677 }
1678
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001679 @Override
1680 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001681 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001682 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001683 return false;
1684 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001685
1686 final long identity = Binder.clearCallingIdentity();
1687 try {
1688 return isRadioOnForSubscriber(subId);
1689 } finally {
1690 Binder.restoreCallingIdentity(identity);
1691 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001692 }
1693
1694 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001695 final long identity = Binder.clearCallingIdentity();
1696 try {
1697 final Phone phone = getPhone(subId);
1698 if (phone != null) {
1699 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1700 } else {
1701 return false;
1702 }
1703 } finally {
1704 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001705 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001706 }
1707
1708 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001709 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001710 }
Wink Saville36469e72014-06-11 15:17:00 -07001711
Wink Savilleb564aae2014-10-23 10:18:09 -07001712 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001713 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001714
1715 final long identity = Binder.clearCallingIdentity();
1716 try {
1717 final Phone phone = getPhone(subId);
1718 if (phone != null) {
1719 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1720 }
1721 } finally {
1722 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001723 }
Wink Saville36469e72014-06-11 15:17:00 -07001724 }
1725
1726 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001727 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001728 }
1729
Wink Savilleb564aae2014-10-23 10:18:09 -07001730 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001731 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001732
1733 final long identity = Binder.clearCallingIdentity();
1734 try {
1735 final Phone phone = getPhone(subId);
1736 if (phone == null) {
1737 return false;
1738 }
1739 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1740 toggleRadioOnOffForSubscriber(subId);
1741 }
1742 return true;
1743 } finally {
1744 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001745 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001746 }
Wink Saville36469e72014-06-11 15:17:00 -07001747
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001748 public boolean needMobileRadioShutdown() {
1749 /*
1750 * If any of the Radios are available, it will need to be
1751 * shutdown. So return true if any Radio is available.
1752 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001753 final long identity = Binder.clearCallingIdentity();
1754 try {
1755 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1756 Phone phone = PhoneFactory.getPhone(i);
1757 if (phone != null && phone.isRadioAvailable()) return true;
1758 }
1759 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1760 return false;
1761 } finally {
1762 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001763 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001764 }
1765
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001766 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001767 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001768 enforceModifyPermission();
1769
1770 final long identity = Binder.clearCallingIdentity();
1771 try {
1772 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1773 logv("Shutting down Phone " + i);
1774 shutdownRadioUsingPhoneId(i);
1775 }
1776 } finally {
1777 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001778 }
1779 }
1780
1781 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001782 Phone phone = PhoneFactory.getPhone(phoneId);
1783 if (phone != null && phone.isRadioAvailable()) {
1784 phone.shutdownRadio();
1785 }
1786 }
1787
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001788 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001789 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001790
1791 final long identity = Binder.clearCallingIdentity();
1792 try {
1793 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1794 if (defaultPhone != null) {
1795 defaultPhone.setRadioPower(turnOn);
1796 return true;
1797 } else {
1798 loge("There's no default phone.");
1799 return false;
1800 }
1801 } finally {
1802 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001803 }
Wink Saville36469e72014-06-11 15:17:00 -07001804 }
1805
Wink Savilleb564aae2014-10-23 10:18:09 -07001806 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001807 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001808
1809 final long identity = Binder.clearCallingIdentity();
1810 try {
1811 final Phone phone = getPhone(subId);
1812 if (phone != null) {
1813 phone.setRadioPower(turnOn);
1814 return true;
1815 } else {
1816 return false;
1817 }
1818 } finally {
1819 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001820 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001821 }
1822
Wink Saville36469e72014-06-11 15:17:00 -07001823 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001824 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001825 public boolean enableDataConnectivity() {
1826 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001827
1828 final long identity = Binder.clearCallingIdentity();
1829 try {
1830 int subId = mSubscriptionController.getDefaultDataSubId();
1831 final Phone phone = getPhone(subId);
1832 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001833 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001834 return true;
1835 } else {
1836 return false;
1837 }
1838 } finally {
1839 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001840 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001841 }
1842
Wink Saville36469e72014-06-11 15:17:00 -07001843 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001844 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001845 public boolean disableDataConnectivity() {
1846 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001847
1848 final long identity = Binder.clearCallingIdentity();
1849 try {
1850 int subId = mSubscriptionController.getDefaultDataSubId();
1851 final Phone phone = getPhone(subId);
1852 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001853 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001854 return true;
1855 } else {
1856 return false;
1857 }
1858 } finally {
1859 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001860 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001861 }
1862
Sanket Padawe356d7632015-06-22 14:03:32 -07001863 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001864 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001865 final long identity = Binder.clearCallingIdentity();
1866 try {
1867 final Phone phone = getPhone(subId);
1868 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001869 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001870 } else {
1871 return false;
1872 }
1873 } finally {
1874 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001875 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001876 }
1877
1878 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001879 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001880 }
1881
pkanwarae03a6b2016-11-06 20:37:09 -08001882 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001883 enforceCallPermission();
1884
1885 final long identity = Binder.clearCallingIdentity();
1886 try {
1887 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1888 return;
1889 }
1890 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1891 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1892 } finally {
1893 Binder.restoreCallingIdentity(identity);
1894 }
pkanwar32d516d2016-10-14 19:37:38 -07001895 };
1896
Wink Savilleb564aae2014-10-23 10:18:09 -07001897 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001898 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001899
1900 final long identity = Binder.clearCallingIdentity();
1901 try {
1902 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1903 return false;
1904 }
1905 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1906 } finally {
1907 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001908 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001909 }
1910
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001911 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001912 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001913 }
1914
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001915 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001916 final long identity = Binder.clearCallingIdentity();
1917 try {
1918 Phone phone = PhoneFactory.getPhone(slotIndex);
1919 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1920 PhoneConstantConversions.convertCallState(phone.getState());
1921 } finally {
1922 Binder.restoreCallingIdentity(identity);
1923 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001924 }
1925
Sanket Padawe356d7632015-06-22 14:03:32 -07001926 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001927 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001928 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
1929 }
1930
1931 @Override
1932 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001933 final long identity = Binder.clearCallingIdentity();
1934 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001935 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001936 if (phone != null) {
1937 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1938 } else {
1939 return PhoneConstantConversions.convertDataState(
1940 PhoneConstants.DataState.DISCONNECTED);
1941 }
1942 } finally {
1943 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001944 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001945 }
1946
Sanket Padawe356d7632015-06-22 14:03:32 -07001947 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001948 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001949 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
1950 }
1951
1952 @Override
1953 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001954 final long identity = Binder.clearCallingIdentity();
1955 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001956 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001957 if (phone != null) {
1958 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1959 } else {
1960 return TelephonyManager.DATA_ACTIVITY_NONE;
1961 }
1962 } finally {
1963 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001964 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001965 }
1966
1967 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001968 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001969 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001970 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08001971
1972 LocationAccessPolicy.LocationPermissionResult locationResult =
1973 LocationAccessPolicy.checkLocationPermission(mApp,
1974 new LocationAccessPolicy.LocationPermissionQuery.Builder()
1975 .setCallingPackage(callingPackage)
1976 .setCallingPid(Binder.getCallingPid())
1977 .setCallingUid(Binder.getCallingUid())
1978 .setMethod("getCellLocation")
1979 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
1980 .build());
1981 switch (locationResult) {
1982 case DENIED_HARD:
1983 throw new SecurityException("Not allowed to access cell location");
1984 case DENIED_SOFT:
1985 return new Bundle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001986 }
1987
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001988 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001989 final long identity = Binder.clearCallingIdentity();
1990 try {
1991 if (DBG_LOC) log("getCellLocation: is active user");
1992 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001993 int subId = mSubscriptionController.getDefaultDataSubId();
1994 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1995 cl.fillInNotifierBundle(data);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001996 return data;
1997 } finally {
1998 Binder.restoreCallingIdentity(identity);
1999 }
Svetoslav64fad262015-04-14 14:35:21 -07002000 }
2001
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002002 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002003 public String getNetworkCountryIsoForPhone(int phoneId) {
2004 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2005 // registered cell info, so return a NULL country instead.
2006 final long identity = Binder.clearCallingIdentity();
2007 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002008 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2009 // Get default phone in this case.
2010 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2011 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002012 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07002013 // Todo: fix this when we can get the actual cellular network info when the device
2014 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002015 if (TelephonyManager.NETWORK_TYPE_IWLAN
2016 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
2017 return "";
2018 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002019 Phone phone = PhoneFactory.getPhone(phoneId);
2020 if (phone != null) {
2021 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07002022 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002023 if (sst != null) {
2024 LocaleTracker lt = sst.getLocaleTracker();
2025 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07002026 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
2027 return lt.getCurrentCountry();
2028 } else if (emergencyNumberTracker != null) {
2029 return emergencyNumberTracker.getEmergencyCountryIso();
2030 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002031 }
2032 }
2033 }
2034 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002035 } finally {
2036 Binder.restoreCallingIdentity(identity);
2037 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002038 }
2039
2040 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002041 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002042 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002043 }
2044
Sanket Padawe356d7632015-06-22 14:03:32 -07002045 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002046 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002047 mApp.enforceCallingOrSelfPermission(
2048 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002049
2050 final long identity = Binder.clearCallingIdentity();
2051 try {
2052 final Phone phone = getPhone(subId);
2053 if (phone != null) {
2054 phone.enableLocationUpdates();
2055 }
2056 } finally {
2057 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002058 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002059 }
2060
2061 @Override
2062 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002063 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002064 }
2065
Sanket Padawe356d7632015-06-22 14:03:32 -07002066 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002067 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002068 mApp.enforceCallingOrSelfPermission(
2069 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002070
2071 final long identity = Binder.clearCallingIdentity();
2072 try {
2073 final Phone phone = getPhone(subId);
2074 if (phone != null) {
2075 phone.disableLocationUpdates();
2076 }
2077 } finally {
2078 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002079 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002080 }
2081
Nathan Harold31d7ff32018-10-15 20:20:30 -07002082 /**
2083 * Returns the target SDK version number for a given package name.
2084 *
Nathan Haroldec184742019-07-10 17:04:16 -07002085 * This call MUST be invoked before clearing the calling UID.
2086 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002087 * @return target SDK if the package is found or INT_MAX.
2088 */
2089 private int getTargetSdk(String packageName) {
2090 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002091 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu54d20302019-07-30 15:12:06 -07002092 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002093 if (ai != null) return ai.targetSdkVersion;
2094 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002095 loge("Failed to get package info for pkg="
2096 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002097 }
2098 return Integer.MAX_VALUE;
2099 }
2100
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002101 @Override
2102 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07002103 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
2104 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002105 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2106 throw new SecurityException(
2107 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2108 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002109
Jordan Liu1617b712019-07-10 15:06:26 -07002110 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002111 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2112 return null;
2113 }
Svetoslav64fad262015-04-14 14:35:21 -07002114
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002115 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002116
Nathan Haroldf180aac2018-06-01 18:43:55 -07002117 List<CellInfo> info = getAllCellInfo(callingPackage);
2118 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002119
Nathan Haroldf180aac2018-06-01 18:43:55 -07002120 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2121 for (CellInfo ci : info) {
2122 if (ci instanceof CellInfoGsm) {
2123 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2124 } else if (ci instanceof CellInfoWcdma) {
2125 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2126 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002127 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002128 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002129 }
2130
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002131 private List<CellInfo> getCachedCellInfo() {
2132 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2133 for (Phone phone : PhoneFactory.getPhones()) {
2134 List<CellInfo> info = phone.getAllCellInfo();
2135 if (info != null) cellInfos.addAll(info);
2136 }
2137 return cellInfos;
2138 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002139
2140 @Override
Svetoslav64fad262015-04-14 14:35:21 -07002141 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002142 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002143 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002144
2145 LocationAccessPolicy.LocationPermissionResult locationResult =
2146 LocationAccessPolicy.checkLocationPermission(mApp,
2147 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2148 .setCallingPackage(callingPackage)
2149 .setCallingPid(Binder.getCallingPid())
2150 .setCallingUid(Binder.getCallingUid())
2151 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002152 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002153 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2154 .build());
2155 switch (locationResult) {
2156 case DENIED_HARD:
2157 throw new SecurityException("Not allowed to access cell info");
2158 case DENIED_SOFT:
2159 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002160 }
2161
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002162 final int targetSdk = getTargetSdk(callingPackage);
2163 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2164 return getCachedCellInfo();
2165 }
2166
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002167 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002168 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002169 final long identity = Binder.clearCallingIdentity();
2170 try {
2171 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2172 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002173 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002174 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002175 if (info != null) cellInfos.addAll(info);
2176 }
2177 return cellInfos;
2178 } finally {
2179 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002180 }
2181 }
2182
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002183 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002184 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2185 requestCellInfoUpdateInternal(
2186 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2187 }
2188
2189 @Override
2190 public void requestCellInfoUpdateWithWorkSource(
2191 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2192 enforceModifyPermission();
2193 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2194 }
2195
2196 private void requestCellInfoUpdateInternal(
2197 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002198 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002199 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002200
2201 LocationAccessPolicy.LocationPermissionResult locationResult =
2202 LocationAccessPolicy.checkLocationPermission(mApp,
2203 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2204 .setCallingPackage(callingPackage)
2205 .setCallingPid(Binder.getCallingPid())
2206 .setCallingUid(Binder.getCallingUid())
2207 .setMethod("requestCellInfoUpdate")
2208 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2209 .build());
2210 switch (locationResult) {
2211 case DENIED_HARD:
2212 throw new SecurityException("Not allowed to access cell info");
2213 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002214 try {
2215 cb.onCellInfo(new ArrayList<CellInfo>());
2216 } catch (RemoteException re) {
2217 // Drop without consequences
2218 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002219 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002220 }
2221
Nathan Harolda939a962019-05-09 10:13:47 -07002222
2223 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002224 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2225
2226 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2227 }
2228
2229 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002230 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002231 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002232 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002233
2234 final long identity = Binder.clearCallingIdentity();
2235 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002236 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002237 } finally {
2238 Binder.restoreCallingIdentity(identity);
2239 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002240 }
2241
Shishir Agrawala9f32182016-04-12 12:00:16 -07002242 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002243 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002244 Phone phone = PhoneFactory.getPhone(slotIndex);
2245 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002246 return null;
2247 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002248 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002249 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2250 callingPackage, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002251 return null;
2252 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002253
2254 final long identity = Binder.clearCallingIdentity();
2255 try {
2256 return phone.getImei();
2257 } finally {
2258 Binder.restoreCallingIdentity(identity);
2259 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002260 }
2261
2262 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002263 public String getTypeAllocationCodeForSlot(int slotIndex) {
2264 Phone phone = PhoneFactory.getPhone(slotIndex);
2265 String tac = null;
2266 if (phone != null) {
2267 String imei = phone.getImei();
2268 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2269 }
2270 return tac;
2271 }
2272
2273 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002274 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002275 Phone phone = PhoneFactory.getPhone(slotIndex);
2276 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002277 return null;
2278 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002279
Jeff Davidson913390f2018-02-23 17:11:49 -08002280 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002281 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2282 callingPackage, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002283 return null;
2284 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002285
2286 final long identity = Binder.clearCallingIdentity();
2287 try {
2288 return phone.getMeid();
2289 } finally {
2290 Binder.restoreCallingIdentity(identity);
2291 }
Jack Yu2af8d712017-03-15 17:14:14 -07002292 }
2293
2294 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002295 public String getManufacturerCodeForSlot(int slotIndex) {
2296 Phone phone = PhoneFactory.getPhone(slotIndex);
2297 String manufacturerCode = null;
2298 if (phone != null) {
2299 String meid = phone.getMeid();
2300 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2301 }
2302 return manufacturerCode;
2303 }
2304
2305 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002306 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002307 Phone phone = PhoneFactory.getPhone(slotIndex);
2308 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002309 return null;
2310 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002311 int subId = phone.getSubId();
2312 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2313 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2314 return null;
2315 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002316
2317 final long identity = Binder.clearCallingIdentity();
2318 try {
2319 return phone.getDeviceSvn();
2320 } finally {
2321 Binder.restoreCallingIdentity(identity);
2322 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002323 }
2324
fionaxu43304da2017-11-27 22:51:16 -08002325 @Override
2326 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002327 final long identity = Binder.clearCallingIdentity();
2328 try {
2329 final Phone phone = getPhone(subId);
2330 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2331 } finally {
2332 Binder.restoreCallingIdentity(identity);
2333 }
fionaxu43304da2017-11-27 22:51:16 -08002334 }
2335
2336 @Override
2337 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002338 final long identity = Binder.clearCallingIdentity();
2339 try {
2340 final Phone phone = getPhone(subId);
2341 return phone == null ? null : phone.getCarrierName();
2342 } finally {
2343 Binder.restoreCallingIdentity(identity);
2344 }
fionaxu43304da2017-11-27 22:51:16 -08002345 }
2346
calvinpanffe225e2018-11-01 19:43:06 +08002347 @Override
chen xu0026ca62019-03-06 15:28:50 -08002348 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002349 final long identity = Binder.clearCallingIdentity();
2350 try {
2351 final Phone phone = getPhone(subId);
2352 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002353 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002354 } finally {
2355 Binder.restoreCallingIdentity(identity);
2356 }
2357 }
2358
2359 @Override
chen xu0026ca62019-03-06 15:28:50 -08002360 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002361 final long identity = Binder.clearCallingIdentity();
2362 try {
2363 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002364 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002365 } finally {
2366 Binder.restoreCallingIdentity(identity);
2367 }
2368 }
2369
chen xu651eec72018-11-11 19:03:44 -08002370 @Override
chen xu864e11c2018-12-06 22:10:03 -08002371 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2372 if (!isSubscriptionMccMnc) {
2373 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2374 }
chen xu651eec72018-11-11 19:03:44 -08002375 final Phone phone = PhoneFactory.getPhone(slotIndex);
2376 if (phone == null) {
2377 return TelephonyManager.UNKNOWN_CARRIER_ID;
2378 }
2379 final long identity = Binder.clearCallingIdentity();
2380 try {
2381 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2382 } finally {
2383 Binder.restoreCallingIdentity(identity);
2384 }
2385 }
2386
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002387 //
2388 // Internal helper methods.
2389 //
2390
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002391 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002392 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2393 *
2394 * @throws SecurityException if the caller does not have the required permission
2395 */
2396 private void enforceModifyPermission() {
2397 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2398 }
2399
2400 /**
2401 * Make sure the caller has the CALL_PHONE permission.
2402 *
2403 * @throws SecurityException if the caller does not have the required permission
2404 */
2405 private void enforceCallPermission() {
2406 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2407 }
2408
Stuart Scott8eef64f2015-04-08 15:13:54 -07002409 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002410 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002411 "ConnectivityService");
2412 }
2413
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002414 private String createTelUrl(String number) {
2415 if (TextUtils.isEmpty(number)) {
2416 return null;
2417 }
2418
Jake Hambye994d462014-02-03 13:10:13 -08002419 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002420 }
2421
Ihab Awadf9e92732013-12-05 18:02:52 -08002422 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002423 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2424 }
2425
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002426 private static void logv(String msg) {
2427 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2428 }
2429
Ihab Awadf9e92732013-12-05 18:02:52 -08002430 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002431 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2432 }
2433
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002434 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002435 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002436 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002437 }
2438
Sanket Padawe356d7632015-06-22 14:03:32 -07002439 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002440 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002441 final long identity = Binder.clearCallingIdentity();
2442 try {
2443 final Phone phone = PhoneFactory.getPhone(slotIndex);
2444 if (phone == null) {
2445 return PhoneConstants.PHONE_TYPE_NONE;
2446 } else {
2447 return phone.getPhoneType();
2448 }
2449 } finally {
2450 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002451 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002452 }
2453
2454 /**
2455 * Returns the CDMA ERI icon index to display
2456 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002457 @Override
2458 public int getCdmaEriIconIndex(String callingPackage) {
2459 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002460 }
2461
Sanket Padawe356d7632015-06-22 14:03:32 -07002462 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002463 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002464 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002465 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002466 return -1;
2467 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002468
2469 final long identity = Binder.clearCallingIdentity();
2470 try {
2471 final Phone phone = getPhone(subId);
2472 if (phone != null) {
2473 return phone.getCdmaEriIconIndex();
2474 } else {
2475 return -1;
2476 }
2477 } finally {
2478 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002479 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002480 }
2481
2482 /**
2483 * Returns the CDMA ERI icon mode,
2484 * 0 - ON
2485 * 1 - FLASHING
2486 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002487 @Override
2488 public int getCdmaEriIconMode(String callingPackage) {
2489 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002490 }
2491
Sanket Padawe356d7632015-06-22 14:03:32 -07002492 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002493 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002494 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002495 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002496 return -1;
2497 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002498
2499 final long identity = Binder.clearCallingIdentity();
2500 try {
2501 final Phone phone = getPhone(subId);
2502 if (phone != null) {
2503 return phone.getCdmaEriIconMode();
2504 } else {
2505 return -1;
2506 }
2507 } finally {
2508 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002509 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002510 }
2511
2512 /**
2513 * Returns the CDMA ERI text,
2514 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002515 @Override
2516 public String getCdmaEriText(String callingPackage) {
2517 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002518 }
2519
Sanket Padawe356d7632015-06-22 14:03:32 -07002520 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002521 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002522 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002523 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002524 return null;
2525 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002526
2527 final long identity = Binder.clearCallingIdentity();
2528 try {
2529 final Phone phone = getPhone(subId);
2530 if (phone != null) {
2531 return phone.getCdmaEriText();
2532 } else {
2533 return null;
2534 }
2535 } finally {
2536 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002537 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002538 }
2539
2540 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002541 * Returns the CDMA MDN.
2542 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002543 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002544 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002545 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2546 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002547
2548 final long identity = Binder.clearCallingIdentity();
2549 try {
2550 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002551 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002552 return phone.getLine1Number();
2553 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002554 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002555 return null;
2556 }
2557 } finally {
2558 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002559 }
2560 }
2561
2562 /**
2563 * Returns the CDMA MIN.
2564 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002565 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002566 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002567 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2568 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002569
2570 final long identity = Binder.clearCallingIdentity();
2571 try {
2572 final Phone phone = getPhone(subId);
2573 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2574 return phone.getCdmaMin();
2575 } else {
2576 return null;
2577 }
2578 } finally {
2579 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002580 }
2581 }
2582
Hall Liud892bec2018-11-30 14:51:45 -08002583 @Override
2584 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2585 INumberVerificationCallback callback, String callingPackage) {
2586 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2587 != PERMISSION_GRANTED) {
2588 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2589 }
2590 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2591
2592 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2593 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2594 throw new SecurityException("Calling package must be configured in the device config");
2595 }
2596
2597 if (range == null) {
2598 throw new NullPointerException("Range must be non-null");
2599 }
2600
2601 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002602 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002603
2604 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2605 }
2606
Junda Liuca05d5d2014-08-14 22:36:34 -07002607 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002608 * Returns true if CDMA provisioning needs to run.
2609 */
2610 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002611 final long identity = Binder.clearCallingIdentity();
2612 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002613 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002614 } finally {
2615 Binder.restoreCallingIdentity(identity);
2616 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002617 }
2618
2619 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002620 * Sets the voice mail number of a given subId.
2621 */
2622 @Override
2623 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002624 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002625
2626 final long identity = Binder.clearCallingIdentity();
2627 try {
2628 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2629 new Pair<String, String>(alphaTag, number), new Integer(subId));
2630 return success;
2631 } finally {
2632 Binder.restoreCallingIdentity(identity);
2633 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002634 }
2635
Ta-wei Yen87c49842016-05-13 21:19:52 -07002636 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002637 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2638 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002639 String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002640 if (!TextUtils.equals(callingPackage, systemDialer)) {
2641 throw new SecurityException("caller must be system dialer");
2642 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002643
2644 final long identity = Binder.clearCallingIdentity();
2645 try {
2646 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2647 if (phoneAccountHandle == null) {
2648 return null;
2649 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002650 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002651 } finally {
2652 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002653 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002654 }
2655
2656 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002657 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002658 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002659 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002660 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002661 return null;
2662 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002663
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002664 final long identity = Binder.clearCallingIdentity();
2665 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002666 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002667 } finally {
2668 Binder.restoreCallingIdentity(identity);
2669 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002670 }
2671
2672 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002673 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2674 VisualVoicemailSmsFilterSettings settings) {
2675 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002676
2677 final long identity = Binder.clearCallingIdentity();
2678 try {
2679 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002680 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002681 } finally {
2682 Binder.restoreCallingIdentity(identity);
2683 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002684 }
2685
2686 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002687 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2688 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002689
2690 final long identity = Binder.clearCallingIdentity();
2691 try {
2692 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002693 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002694 } finally {
2695 Binder.restoreCallingIdentity(identity);
2696 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002697 }
2698
2699 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002700 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2701 String callingPackage, int subId) {
2702 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002703
2704 final long identity = Binder.clearCallingIdentity();
2705 try {
2706 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002707 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002708 } finally {
2709 Binder.restoreCallingIdentity(identity);
2710 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002711 }
2712
2713 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002714 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002715 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002716
2717 final long identity = Binder.clearCallingIdentity();
2718 try {
2719 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002720 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002721 } finally {
2722 Binder.restoreCallingIdentity(identity);
2723 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002724 }
2725
2726 @Override
2727 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2728 String number, int port, String text, PendingIntent sentIntent) {
2729 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002730 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002731 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07002732 SmsController smsController = PhoneFactory.getSmsController();
2733 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
2734 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002735 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07002736
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002737 /**
fionaxu0152e512016-11-14 13:36:14 -08002738 * Sets the voice activation state of a given subId.
2739 */
2740 @Override
2741 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002742 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2743 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002744
2745 final long identity = Binder.clearCallingIdentity();
2746 try {
2747 final Phone phone = getPhone(subId);
2748 if (phone != null) {
2749 phone.setVoiceActivationState(activationState);
2750 } else {
2751 loge("setVoiceActivationState fails with invalid subId: " + subId);
2752 }
2753 } finally {
2754 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002755 }
2756 }
2757
2758 /**
2759 * Sets the data activation state of a given subId.
2760 */
2761 @Override
2762 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002763 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2764 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002765
2766 final long identity = Binder.clearCallingIdentity();
2767 try {
2768 final Phone phone = getPhone(subId);
2769 if (phone != null) {
2770 phone.setDataActivationState(activationState);
2771 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09002772 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002773 }
2774 } finally {
2775 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002776 }
2777 }
2778
2779 /**
2780 * Returns the voice activation state of a given subId.
2781 */
2782 @Override
2783 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002784 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002785
fionaxu0152e512016-11-14 13:36:14 -08002786 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002787 final long identity = Binder.clearCallingIdentity();
2788 try {
2789 if (phone != null) {
2790 return phone.getVoiceActivationState();
2791 } else {
2792 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2793 }
2794 } finally {
2795 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002796 }
2797 }
2798
2799 /**
2800 * Returns the data activation state of a given subId.
2801 */
2802 @Override
2803 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002804 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002805
fionaxu0152e512016-11-14 13:36:14 -08002806 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002807 final long identity = Binder.clearCallingIdentity();
2808 try {
2809 if (phone != null) {
2810 return phone.getDataActivationState();
2811 } else {
2812 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2813 }
2814 } finally {
2815 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002816 }
2817 }
2818
2819 /**
Wink Saville36469e72014-06-11 15:17:00 -07002820 * Returns the unread count of voicemails for a subId
2821 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002822 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002823 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2824 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2825 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2826 return 0;
2827 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002828 final long identity = Binder.clearCallingIdentity();
2829 try {
2830 final Phone phone = getPhone(subId);
2831 if (phone != null) {
2832 return phone.getVoiceMessageCount();
2833 } else {
2834 return 0;
2835 }
2836 } finally {
2837 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002838 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002839 }
2840
2841 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002842 * returns true, if the device is in a state where both voice and data
2843 * are supported simultaneously. This can change based on location or network condition.
2844 */
2845 @Override
2846 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002847 final long identity = Binder.clearCallingIdentity();
2848 try {
2849 final Phone phone = getPhone(subId);
2850 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2851 } finally {
2852 Binder.restoreCallingIdentity(identity);
2853 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002854 }
2855
2856 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002857 * Send the dialer code if called from the current default dialer or the caller has
2858 * carrier privilege.
2859 * @param inputCode The dialer code to send
2860 */
2861 @Override
2862 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002863 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002864 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002865 String defaultDialer = TelecomManager.from(defaultPhone.getContext())
2866 .getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002867 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002868 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2869 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002870 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002871
2872 final long identity = Binder.clearCallingIdentity();
2873 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002874 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002875 } finally {
2876 Binder.restoreCallingIdentity(identity);
2877 }
fionaxu235cc5e2017-03-06 22:25:57 -08002878 }
2879
Pengquan Menga1bb6272018-09-06 09:59:22 -07002880 @Override
2881 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002882 if (!isActiveSubscription(subId)) {
2883 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2884 }
2885
Pengquan Menga1bb6272018-09-06 09:59:22 -07002886 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2887 }
2888
Brad Ebinger35c841c2018-10-01 10:40:55 -07002889 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002890 public boolean isInEmergencySmsMode() {
2891 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2892 final long identity = Binder.clearCallingIdentity();
2893 try {
2894 for (Phone phone : PhoneFactory.getPhones()) {
2895 if (phone.isInEmergencySmsMode()) {
2896 return true;
2897 }
2898 }
2899 } finally {
2900 Binder.restoreCallingIdentity(identity);
2901 }
2902 return false;
2903 }
2904
2905 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002906 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2907 throws RemoteException {
2908 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002909 final long token = Binder.clearCallingIdentity();
2910 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002911 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002912 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002913 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002914 } catch (ImsException e) {
2915 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002916 } finally {
2917 Binder.restoreCallingIdentity(token);
2918 }
2919 }
2920
2921 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002922 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2923 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002924 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2925 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2926 }
2927 Binder.withCleanCallingIdentity(() -> {
2928 try {
2929 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002930 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002931 .removeRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002932 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002933 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2934 + "is inactive, ignoring unregister.");
2935 // If the subscription is no longer active, just return, since the callback
2936 // will already have been removed internally.
2937 }
2938 });
Brad Ebinger35c841c2018-10-01 10:40:55 -07002939 }
2940
2941 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002942 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2943 throws RemoteException {
2944 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002945 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2946 final long token = Binder.clearCallingIdentity();
2947 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002948 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002949 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002950 } catch (ImsException e) {
2951 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002952 } finally {
2953 Binder.restoreCallingIdentity(token);
2954 }
2955 }
2956
2957 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002958 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2959 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002960
2961 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2962 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2963 }
2964 Binder.withCleanCallingIdentity(() -> {
2965 try {
2966 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002967 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002968 .removeCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002969 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002970 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
2971 + "is inactive, ignoring unregister.");
2972 // If the subscription is no longer active, just return, since the callback
2973 // will already have been removed internally.
2974 }
2975 });
Brad Ebinger35c841c2018-10-01 10:40:55 -07002976 }
2977
2978 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002979 public boolean isCapable(int subId, int capability, int regTech) {
2980 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002981 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2982 final long token = Binder.clearCallingIdentity();
2983 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002984 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002985 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002986 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002987 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2988 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002989 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08002990 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
2991 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07002992 } finally {
2993 Binder.restoreCallingIdentity(token);
2994 }
2995 }
2996
2997 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002998 public boolean isAvailable(int subId, int capability, int regTech) {
2999 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003000 final long token = Binder.clearCallingIdentity();
3001 try {
3002 Phone phone = getPhone(subId);
3003 if (phone == null) return false;
3004 return phone.isImsCapabilityAvailable(capability, regTech);
3005 } finally {
3006 Binder.restoreCallingIdentity(token);
3007 }
3008 }
3009
3010 @Override
3011 public boolean isAdvancedCallingSettingEnabled(int subId) {
3012 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
3013 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3014 final long token = Binder.clearCallingIdentity();
3015 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003016 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003017 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003018 } catch (ImsException e) {
3019 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003020 } finally {
3021 Binder.restoreCallingIdentity(token);
3022 }
3023 }
3024
3025 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003026 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003027 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003028 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003029 final long identity = Binder.clearCallingIdentity();
3030 try {
3031 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003032 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003033 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003034 } catch (ImsException e) {
3035 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003036 } finally {
3037 Binder.restoreCallingIdentity(identity);
3038 }
3039 }
3040
3041 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003042 public boolean isVtSettingEnabled(int subId) {
3043 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003044 final long identity = Binder.clearCallingIdentity();
3045 try {
3046 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003047 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3048 } catch (ImsException e) {
3049 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003050 } finally {
3051 Binder.restoreCallingIdentity(identity);
3052 }
3053 }
3054
3055 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003056 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003057 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003058 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003059 final long identity = Binder.clearCallingIdentity();
3060 try {
3061 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003062 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003063 } catch (ImsException e) {
3064 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003065 } finally {
3066 Binder.restoreCallingIdentity(identity);
3067 }
3068 }
3069
3070 @Override
3071 public boolean isVoWiFiSettingEnabled(int subId) {
3072 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3073 final long identity = Binder.clearCallingIdentity();
3074 try {
3075 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003076 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003077 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003078 } catch (ImsException e) {
3079 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003080 } finally {
3081 Binder.restoreCallingIdentity(identity);
3082 }
3083 }
3084
3085 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003086 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003087 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003088 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003089 final long identity = Binder.clearCallingIdentity();
3090 try {
3091 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003092 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003093 } catch (ImsException e) {
3094 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003095 } finally {
3096 Binder.restoreCallingIdentity(identity);
3097 }
3098 }
3099
3100 @Override
3101 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3102 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3103 final long identity = Binder.clearCallingIdentity();
3104 try {
3105 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003106 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003107 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003108 } catch (ImsException e) {
3109 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003110 } finally {
3111 Binder.restoreCallingIdentity(identity);
3112 }
3113 }
3114
3115 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003116 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003117 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003118 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003119 final long identity = Binder.clearCallingIdentity();
3120 try {
3121 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003122 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003123 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003124 } catch (ImsException e) {
3125 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003126 } finally {
3127 Binder.restoreCallingIdentity(identity);
3128 }
3129 }
3130
3131 @Override
3132 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3133 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3134 "setVoWiFiNonPersistent");
3135 final long identity = Binder.clearCallingIdentity();
3136 try {
3137 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003138 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003139 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003140 } catch (ImsException e) {
3141 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003142 } finally {
3143 Binder.restoreCallingIdentity(identity);
3144 }
3145 }
3146
3147 @Override
3148 public int getVoWiFiModeSetting(int subId) {
3149 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3150 final long identity = Binder.clearCallingIdentity();
3151 try {
3152 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003153 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003154 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003155 } catch (ImsException e) {
3156 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003157 } finally {
3158 Binder.restoreCallingIdentity(identity);
3159 }
3160 }
3161
3162 @Override
3163 public void setVoWiFiModeSetting(int subId, int mode) {
3164 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3165 "setVoWiFiModeSetting");
3166 final long identity = Binder.clearCallingIdentity();
3167 try {
3168 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003169 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003170 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003171 } catch (ImsException e) {
3172 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003173 } finally {
3174 Binder.restoreCallingIdentity(identity);
3175 }
3176 }
3177
3178 @Override
3179 public int getVoWiFiRoamingModeSetting(int subId) {
3180 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3181 final long identity = Binder.clearCallingIdentity();
3182 try {
3183 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003184 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003185 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003186 } catch (ImsException e) {
3187 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003188 } finally {
3189 Binder.restoreCallingIdentity(identity);
3190 }
3191 }
3192
3193 @Override
3194 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3195 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3196 "setVoWiFiRoamingModeSetting");
3197 final long identity = Binder.clearCallingIdentity();
3198 try {
3199 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003200 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003201 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003202 } catch (ImsException e) {
3203 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003204 } finally {
3205 Binder.restoreCallingIdentity(identity);
3206 }
3207 }
3208
3209 @Override
3210 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3211 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3212 "setRttCapabilityEnabled");
3213 final long identity = Binder.clearCallingIdentity();
3214 try {
3215 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003216 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3217 } catch (ImsException e) {
3218 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003219 } finally {
3220 Binder.restoreCallingIdentity(identity);
3221 }
3222 }
3223
3224 @Override
3225 public boolean isTtyOverVolteEnabled(int subId) {
3226 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3227 final long identity = Binder.clearCallingIdentity();
3228 try {
3229 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003230 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003231 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003232 } catch (ImsException e) {
3233 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003234 } finally {
3235 Binder.restoreCallingIdentity(identity);
3236 }
3237 }
3238
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003239 @Override
3240 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3241 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3242 final long identity = Binder.clearCallingIdentity();
3243 try {
3244 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003245 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003246 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003247 } catch (ImsException e) {
3248 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003249 } finally {
3250 Binder.restoreCallingIdentity(identity);
3251 }
3252 }
3253
3254 @Override
3255 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3256 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3257 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003258 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3259 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3260 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003261 try {
3262 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003263 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003264 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003265 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003266 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3267 + "is inactive, ignoring unregister.");
3268 // If the subscription is no longer active, just return, since the callback will already
3269 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003270 } finally {
3271 Binder.restoreCallingIdentity(identity);
3272 }
3273 }
3274
3275 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003276 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3277 boolean isProvisioned) {
3278 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3279 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3280 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3281 }
3282 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3283 "setProvisioningStatusForCapability");
3284 final long identity = Binder.clearCallingIdentity();
3285 try {
3286 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3287 Phone phone = getPhone(subId);
3288 if (phone == null) {
3289 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3290 + subId);
3291 return;
3292 }
3293 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3294 return;
3295 }
3296
3297 // this capability requires provisioning, route to the correct API.
3298 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3299 switch (capability) {
3300 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3301 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3302 ims.setVolteProvisioned(isProvisioned);
3303 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3304 ims.setWfcProvisioned(isProvisioned);
3305 }
3306 break;
3307 }
3308 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3309 // There is currently no difference in VT provisioning type.
3310 ims.setVtProvisioned(isProvisioned);
3311 break;
3312 }
3313 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3314 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3315 // change the capability of the feature instead if needed.
3316 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3317 == isProvisioned) {
3318 // No change in provisioning.
3319 return;
3320 }
3321 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3322 try {
3323 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003324 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003325 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3326 + ", Exception" + e.getMessage());
3327 }
3328 break;
3329 }
3330 default: {
3331 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3332 + capability + "', which does not require provisioning.");
3333 }
3334 }
3335
3336 } finally {
3337 Binder.restoreCallingIdentity(identity);
3338 }
3339 }
3340
3341 @Override
3342 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3343 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3344 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3345 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3346 }
3347 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3348 final long identity = Binder.clearCallingIdentity();
3349 try {
3350 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3351 Phone phone = getPhone(subId);
3352 if (phone == null) {
3353 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3354 + subId);
3355 // We will fail with "true" as the provisioning status because this is the default
3356 // if we do not require provisioning.
3357 return true;
3358 }
3359
3360 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3361 return true;
3362 }
3363
3364 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3365 switch (capability) {
3366 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3367 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3368 return ims.isVolteProvisionedOnDevice();
3369 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3370 return ims.isWfcProvisionedOnDevice();
3371 }
3372 // This should never happen, since we are checking tech above to make sure it
3373 // is either LTE or IWLAN.
3374 throw new IllegalArgumentException("Invalid radio technology for voice "
3375 + "capability.");
3376 }
3377 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3378 // There is currently no difference in VT provisioning type.
3379 return ims.isVtProvisionedOnDevice();
3380 }
3381 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3382 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3383 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3384 }
3385 default: {
3386 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3387 + capability + "', which does not require provisioning.");
3388 }
3389 }
3390
3391 } finally {
3392 Binder.restoreCallingIdentity(identity);
3393 }
3394 }
3395
3396 @Override
3397 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3398 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3399 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3400 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3401 }
3402 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3403 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3404 return (provisionedBits & capability) > 0;
3405 }
3406
3407 @Override
3408 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3409 boolean isProvisioned) {
3410 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3411 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3412 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3413 }
3414 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3415 "setProvisioningStatusForCapability");
3416 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3417 // If the current provisioning status for capability already matches isProvisioned,
3418 // do nothing.
3419 if (((provisionedBits & capability) > 0) == isProvisioned) {
3420 return;
3421 }
3422 if (isProvisioned) {
3423 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3424 } else {
3425 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3426 }
3427 }
3428
3429 /**
3430 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3431 * technology. The bitfield should mirror the bitfield defined by
3432 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3433 */
3434 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3435 String key = getMmTelProvisioningKey(subId, tech);
3436 // Default is no capabilities are provisioned.
3437 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3438 }
3439
3440 /**
3441 * Sets the MmTel capability provisioning bitfield (defined by
3442 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3443 * technology specified.
3444 *
3445 * Note: This is a synchronous command and should not be called on UI thread.
3446 */
3447 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3448 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3449 String key = getMmTelProvisioningKey(subId, tech);
3450 editor.putInt(key, newField);
3451 editor.commit();
3452 }
3453
3454 private static String getMmTelProvisioningKey(int subId, int tech) {
3455 // resulting key is provision_ims_mmtel_{subId}_{tech}
3456 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3457 }
3458
3459 /**
3460 * Query CarrierConfig to see if the specified capability requires provisioning for the
3461 * carrier associated with the subscription id.
3462 */
3463 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3464 int capability) {
3465 CarrierConfigManager configManager = new CarrierConfigManager(context);
3466 PersistableBundle c = configManager.getConfigForSubId(subId);
3467 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07003468 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003469 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3470 false);
3471 boolean requireVoiceVtProvisioning = c.getBoolean(
3472 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3473
3474 // First check to make sure that the capability requires provisioning.
3475 switch (capability) {
3476 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3477 // intentional fallthrough
3478 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3479 if (requireVoiceVtProvisioning) {
3480 // Voice and Video requires provisioning
3481 return true;
3482 }
3483 break;
3484 }
3485 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3486 if (requireUtProvisioning) {
3487 // UT requires provisioning
3488 return true;
3489 }
3490 break;
3491 }
3492 }
3493 return false;
3494 }
3495
3496 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003497 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003498 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3499 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3500 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003501 enforceReadPrivilegedPermission("getImsProvisioningInt");
3502 final long identity = Binder.clearCallingIdentity();
3503 try {
3504 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003505 int slotId = getSlotIndex(subId);
3506 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3507 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3508 + subId + "' for key:" + key);
3509 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3510 }
3511 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003512 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003513 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3514 + subId + "' for key:" + key);
3515 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003516 } finally {
3517 Binder.restoreCallingIdentity(identity);
3518 }
3519 }
3520
3521 @Override
3522 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003523 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3524 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3525 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003526 enforceReadPrivilegedPermission("getImsProvisioningString");
3527 final long identity = Binder.clearCallingIdentity();
3528 try {
3529 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003530 int slotId = getSlotIndex(subId);
3531 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3532 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3533 + subId + "' for key:" + key);
3534 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3535 }
3536 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003537 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003538 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3539 + subId + "' for key:" + key);
3540 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003541 } finally {
3542 Binder.restoreCallingIdentity(identity);
3543 }
3544 }
3545
3546 @Override
3547 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003548 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3549 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3550 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003551 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3552 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003553 final long identity = Binder.clearCallingIdentity();
3554 try {
3555 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003556 int slotId = getSlotIndex(subId);
3557 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3558 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3559 + subId + "' for key:" + key);
3560 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3561 }
3562 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003563 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003564 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3565 + "' for key:" + key);
3566 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003567 } finally {
3568 Binder.restoreCallingIdentity(identity);
3569 }
3570 }
3571
3572 @Override
3573 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003574 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3575 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3576 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003577 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3578 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003579 final long identity = Binder.clearCallingIdentity();
3580 try {
3581 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003582 int slotId = getSlotIndex(subId);
3583 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3584 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3585 + subId + "' for key:" + key);
3586 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3587 }
3588 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003589 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003590 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3591 + "' for key:" + key);
3592 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003593 } finally {
3594 Binder.restoreCallingIdentity(identity);
3595 }
3596 }
3597
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003598 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003599 int slotId = SubscriptionManager.getSlotIndex(subId);
3600 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003601 throw new ImsException("Invalid Subscription Id, subId=" + subId,
3602 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003603 }
3604 return slotId;
3605 }
3606
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003607 private int getSlotIndex(int subId) {
3608 int slotId = SubscriptionManager.getSlotIndex(subId);
3609 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3610 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3611 }
3612 return slotId;
3613 }
3614
Wink Saville36469e72014-06-11 15:17:00 -07003615 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07003616 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07003617 */
3618 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003619 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07003620 final int targetSdk = getTargetSdk(callingPackage);
3621 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
3622 return getDataNetworkTypeForSubscriber(subId, callingPackage);
3623 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07003624 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
3625 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003626 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3627 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003628
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003629 final long identity = Binder.clearCallingIdentity();
3630 try {
3631 final Phone phone = getPhone(subId);
3632 if (phone != null) {
3633 return phone.getServiceState().getDataNetworkType();
3634 } else {
3635 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3636 }
3637 } finally {
3638 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003639 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003640 }
3641
3642 /**
3643 * Returns the data network type
3644 */
3645 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003646 public int getDataNetworkType(String callingPackage) {
3647 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003648 }
3649
3650 /**
3651 * Returns the data network type for a subId
3652 */
3653 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003654 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003655 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003656 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003657 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3658 }
3659
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003660 final long identity = Binder.clearCallingIdentity();
3661 try {
3662 final Phone phone = getPhone(subId);
3663 if (phone != null) {
3664 return phone.getServiceState().getDataNetworkType();
3665 } else {
3666 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3667 }
3668 } finally {
3669 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003670 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003671 }
3672
3673 /**
Wink Saville36469e72014-06-11 15:17:00 -07003674 * Returns the Voice network type for a subId
3675 */
3676 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003677 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003678 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003679 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003680 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3681 }
3682
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003683 final long identity = Binder.clearCallingIdentity();
3684 try {
3685 final Phone phone = getPhone(subId);
3686 if (phone != null) {
3687 return phone.getServiceState().getVoiceNetworkType();
3688 } else {
3689 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3690 }
3691 } finally {
3692 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003693 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003694 }
3695
3696 /**
3697 * @return true if a ICC card is present
3698 */
3699 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003700 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003701 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3702 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003703 }
3704
3705 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003706 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003707 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003708 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003709 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003710 final long identity = Binder.clearCallingIdentity();
3711 try {
3712 final Phone phone = PhoneFactory.getPhone(slotIndex);
3713 if (phone != null) {
3714 return phone.getIccCard().hasIccCard();
3715 } else {
3716 return false;
3717 }
3718 } finally {
3719 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003720 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003721 }
3722
3723 /**
3724 * Return if the current radio is LTE on CDMA. This
3725 * is a tri-state return value as for a period of time
3726 * the mode may be unknown.
3727 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003728 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003729 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003730 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003731 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003732 @Override
3733 public int getLteOnCdmaMode(String callingPackage) {
3734 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003735 }
3736
Sanket Padawe356d7632015-06-22 14:03:32 -07003737 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003738 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003739 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003740 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003741 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3742 }
3743
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003744 final long identity = Binder.clearCallingIdentity();
3745 try {
3746 final Phone phone = getPhone(subId);
3747 if (phone == null) {
3748 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3749 } else {
3750 return phone.getLteOnCdmaMode();
3751 }
3752 } finally {
3753 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003754 }
Wink Saville36469e72014-06-11 15:17:00 -07003755 }
3756
Wink Saville36469e72014-06-11 15:17:00 -07003757 /**
3758 * {@hide}
3759 * Returns Default subId, 0 in the case of single standby.
3760 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003761 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003762 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003763 }
3764
Shishir Agrawala9f32182016-04-12 12:00:16 -07003765 private int getSlotForDefaultSubscription() {
3766 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3767 }
3768
Wink Savilleb564aae2014-10-23 10:18:09 -07003769 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003770 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003771 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003772
Pengquan Menge92a50d2018-09-21 15:54:48 -07003773 private boolean isActiveSubscription(int subId) {
3774 return mSubscriptionController.isActiveSubId(subId);
3775 }
3776
Ihab Awadf2177b72013-11-25 13:33:23 -08003777 /**
3778 * @see android.telephony.TelephonyManager.WifiCallingChoices
3779 */
3780 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003781 final long identity = Binder.clearCallingIdentity();
3782 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003783 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003784 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3785 getWhenToMakeWifiCallsDefaultPreference());
3786 } finally {
3787 Binder.restoreCallingIdentity(identity);
3788 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003789 }
3790
3791 /**
3792 * @see android.telephony.TelephonyManager.WifiCallingChoices
3793 */
3794 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003795 final long identity = Binder.clearCallingIdentity();
3796 try {
3797 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003798 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003799 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3800 } finally {
3801 Binder.restoreCallingIdentity(identity);
3802 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003803 }
3804
Sailesh Nepald1e68152013-12-12 19:08:02 -08003805 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003806 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003807 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003808 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003809
Jordan Liu4c733742019-02-28 12:03:40 -08003810 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
3811 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
3812 if (phoneId == -1) {
3813 throw new IllegalArgumentException("Given slot index: " + slotIndex
3814 + " does not correspond to an active phone");
3815 }
3816 return PhoneFactory.getPhone(phoneId);
3817 }
3818
Shishir Agrawal566b7612013-10-28 14:41:00 -07003819 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003820 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3821 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003822 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3823 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003824 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08003825 if (DBG) {
3826 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3827 }
3828 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
3829 p2);
3830 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003831
Jordan Liu4c733742019-02-28 12:03:40 -08003832
3833 @Override
3834 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
3835 int slotIndex, String callingPackage, String aid, int p2) {
3836 enforceModifyPermission();
3837 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3838 if (DBG) {
3839 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
3840 }
3841 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3842 callingPackage, aid, p2);
3843 }
3844
3845 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
3846 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003847 final long identity = Binder.clearCallingIdentity();
3848 try {
3849 if (TextUtils.equals(ISDR_AID, aid)) {
3850 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003851 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3852 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003853 if (bestComponent == null
3854 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3855 loge("The calling package is not allowed to access ISD-R.");
3856 throw new SecurityException(
3857 "The calling package is not allowed to access ISD-R.");
3858 }
Derek Tan740e1672017-06-27 14:56:27 -07003859 }
Derek Tan740e1672017-06-27 14:56:27 -07003860
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003861 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08003862 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
3863 null /* workSource */);
3864 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003865 return response;
3866 } finally {
3867 Binder.restoreCallingIdentity(identity);
3868 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003869 }
3870
3871 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003872 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003873 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3874 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08003875 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3876 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
3877 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003878
Jordan Liu4c733742019-02-28 12:03:40 -08003879 @Override
3880 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
3881 enforceModifyPermission();
3882 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
3883 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3884 channel);
3885 }
3886
3887 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003888 final long identity = Binder.clearCallingIdentity();
3889 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003890 if (channel < 0) {
3891 return false;
3892 }
Jordan Liu4c733742019-02-28 12:03:40 -08003893 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
3894 null /* workSource */);
3895 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003896 return success;
3897 } finally {
3898 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003899 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003900 }
3901
3902 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003903 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003904 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003905 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3906 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08003907 if (DBG) {
3908 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3909 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3910 + p3 + " data=" + data);
3911 }
3912 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
3913 command, p1, p2, p3, data);
3914 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003915
Jordan Liu4c733742019-02-28 12:03:40 -08003916 @Override
3917 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
3918 int command, int p1, int p2, int p3, String data) {
3919 enforceModifyPermission();
3920 if (DBG) {
3921 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
3922 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3923 + p3 + " data=" + data);
3924 }
3925 return iccTransmitApduLogicalChannelWithPermission(
3926 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
3927 data);
3928 }
3929
3930 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
3931 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003932 final long identity = Binder.clearCallingIdentity();
3933 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07003934 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003935 return "";
3936 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003937
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003938 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08003939 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
3940 null /* workSource */);
3941 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003942
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003943 // Append the returned status code to the end of the response payload.
3944 String s = Integer.toHexString(
3945 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3946 if (response.payload != null) {
3947 s = IccUtils.bytesToHexString(response.payload) + s;
3948 }
3949 return s;
3950 } finally {
3951 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003952 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003953 }
Jake Hambye994d462014-02-03 13:10:13 -08003954
Evan Charltonc66da362014-05-16 14:06:40 -07003955 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003956 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3957 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003958 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3959 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003960 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08003961 if (DBG) {
3962 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3963 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3964 }
3965 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
3966 cla, command, p1, p2, p3, data);
3967 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003968
Jordan Liu4c733742019-02-28 12:03:40 -08003969 @Override
3970 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
3971 int command, int p1, int p2, int p3, String data) {
3972 enforceModifyPermission();
3973 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3974 if (DBG) {
3975 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
3976 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
3977 + " data=" + data);
3978 }
3979
3980 return iccTransmitApduBasicChannelWithPermission(
3981 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
3982 p2, p3, data);
3983 }
3984
3985 // open APDU basic channel assuming the caller has sufficient permissions
3986 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
3987 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003988 final long identity = Binder.clearCallingIdentity();
3989 try {
3990 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3991 && TextUtils.equals(ISDR_AID, data)) {
3992 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003993 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3994 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003995 if (bestComponent == null
3996 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3997 loge("The calling package is not allowed to select ISD-R.");
3998 throw new SecurityException(
3999 "The calling package is not allowed to select ISD-R.");
4000 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004001 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004002
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004003 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004004 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4005 null /* workSource */);
4006 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004007
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004008 // Append the returned status code to the end of the response payload.
4009 String s = Integer.toHexString(
4010 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4011 if (response.payload != null) {
4012 s = IccUtils.bytesToHexString(response.payload) + s;
4013 }
4014 return s;
4015 } finally {
4016 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004017 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004018 }
4019
4020 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004021 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004022 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004023 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4024 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004025
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004026 final long identity = Binder.clearCallingIdentity();
4027 try {
4028 if (DBG) {
4029 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4030 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4031 }
4032
4033 IccIoResult response =
4034 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4035 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4036 subId);
4037
4038 if (DBG) {
4039 log("Exchange SIM_IO [R]" + response);
4040 }
4041
4042 byte[] result = null;
4043 int length = 2;
4044 if (response.payload != null) {
4045 length = 2 + response.payload.length;
4046 result = new byte[length];
4047 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4048 } else {
4049 result = new byte[length];
4050 }
4051
4052 result[length - 1] = (byte) response.sw2;
4053 result[length - 2] = (byte) response.sw1;
4054 return result;
4055 } finally {
4056 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004057 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004058 }
4059
Nathan Haroldb3014052017-01-25 15:57:32 -08004060 /**
4061 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4062 * on a particular subscription
4063 */
sqianb6e41952018-03-12 14:54:01 -07004064 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
4065 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4066 mApp, subId, callingPackage, "getForbiddenPlmns")) {
4067 return null;
4068 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004069
4070 final long identity = Binder.clearCallingIdentity();
4071 try {
4072 if (appType != TelephonyManager.APPTYPE_USIM
4073 && appType != TelephonyManager.APPTYPE_SIM) {
4074 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4075 return null;
4076 }
4077 Object response = sendRequest(
4078 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4079 if (response instanceof String[]) {
4080 return (String[]) response;
4081 }
yincheng zhaod698b842019-09-06 17:06:54 -07004082 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004083 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004084 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004085 } finally {
4086 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004087 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004088 }
4089
yincheng zhaod698b842019-09-06 17:06:54 -07004090 /**
4091 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4092 * subscription.
4093 *
4094 * @param subId the id of the subscription.
4095 * @param appType the uicc app type, must be USIM or SIM.
4096 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4097 * @param callingPackage the op Package name.
4098 * @return number of fplmns that is successfully written to the SIM.
4099 */
4100 public int setForbiddenPlmns(
4101 int subId, int appType, List<String> fplmns, String callingPackage) {
4102 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4103 mApp, subId, callingPackage, "setForbiddenPlmns")) {
4104 if (DBG) logv("no permissions for setForbiddenplmns");
4105 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4106 }
4107 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4108 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4109 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4110 }
4111 if (fplmns == null) {
4112 throw new IllegalArgumentException("Fplmn List provided is null");
4113 }
4114 for (String fplmn : fplmns) {
4115 if (!CellIdentity.isValidPlmn(fplmn)) {
4116 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4117 }
4118 }
4119 final long identity = Binder.clearCallingIdentity();
4120 try {
4121 Object response = sendRequest(
4122 CMD_SET_FORBIDDEN_PLMNS,
4123 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4124 subId);
4125 return (int) response;
4126 } finally {
4127 Binder.restoreCallingIdentity(identity);
4128 }
4129 }
4130
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004131 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004132 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004133 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4134 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004135
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004136 final long identity = Binder.clearCallingIdentity();
4137 try {
4138 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4139 if (response.payload == null) {
4140 return "";
4141 }
Evan Charltonc66da362014-05-16 14:06:40 -07004142
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004143 // Append the returned status code to the end of the response payload.
4144 String s = Integer.toHexString(
4145 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4146 s = IccUtils.bytesToHexString(response.payload) + s;
4147 return s;
4148 } finally {
4149 Binder.restoreCallingIdentity(identity);
4150 }
Evan Charltonc66da362014-05-16 14:06:40 -07004151 }
4152
Jake Hambye994d462014-02-03 13:10:13 -08004153 /**
4154 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4155 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4156 *
4157 * @param itemID the ID of the item to read
4158 * @return the NV item as a String, or null on error.
4159 */
4160 @Override
4161 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004162 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004163 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4164 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004165
4166 final long identity = Binder.clearCallingIdentity();
4167 try {
4168 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004169 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004170 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4171 return value;
4172 } finally {
4173 Binder.restoreCallingIdentity(identity);
4174 }
Jake Hambye994d462014-02-03 13:10:13 -08004175 }
4176
4177 /**
4178 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4179 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4180 *
4181 * @param itemID the ID of the item to read
4182 * @param itemValue the value to write, as a String
4183 * @return true on success; false on any failure
4184 */
4185 @Override
4186 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004187 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004188 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4189 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004190
4191 final long identity = Binder.clearCallingIdentity();
4192 try {
4193 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4194 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004195 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004196 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4197 return success;
4198 } finally {
4199 Binder.restoreCallingIdentity(identity);
4200 }
Jake Hambye994d462014-02-03 13:10:13 -08004201 }
4202
4203 /**
4204 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4205 * Used for device configuration by some CDMA operators.
4206 *
4207 * @param preferredRoamingList byte array containing the new PRL
4208 * @return true on success; false on any failure
4209 */
4210 @Override
4211 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004212 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4213 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004214
4215 final long identity = Binder.clearCallingIdentity();
4216 try {
4217 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4218 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4219 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4220 return success;
4221 } finally {
4222 Binder.restoreCallingIdentity(identity);
4223 }
Jake Hambye994d462014-02-03 13:10:13 -08004224 }
4225
4226 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004227 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004228 * Used for device configuration by some CDMA operators.
4229 *
chen xu6dac5ab2018-10-26 17:39:23 -07004230 * @param slotIndex - device slot.
4231 *
Jake Hambye994d462014-02-03 13:10:13 -08004232 * @return true on success; false on any failure
4233 */
4234 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004235 public boolean resetModemConfig(int slotIndex) {
4236 Phone phone = PhoneFactory.getPhone(slotIndex);
4237 if (phone != null) {
4238 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4239 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004240
chen xu6dac5ab2018-10-26 17:39:23 -07004241 final long identity = Binder.clearCallingIdentity();
4242 try {
4243 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4244 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4245 return success;
4246 } finally {
4247 Binder.restoreCallingIdentity(identity);
4248 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004249 }
chen xu6dac5ab2018-10-26 17:39:23 -07004250 return false;
4251 }
4252
4253 /**
4254 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4255 *
4256 * @param slotIndex - device slot.
4257 *
4258 * @return true on success; false on any failure
4259 */
4260 @Override
4261 public boolean rebootModem(int slotIndex) {
4262 Phone phone = PhoneFactory.getPhone(slotIndex);
4263 if (phone != null) {
4264 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4265 mApp, phone.getSubId(), "rebootModem");
4266
4267 final long identity = Binder.clearCallingIdentity();
4268 try {
4269 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4270 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4271 return success;
4272 } finally {
4273 Binder.restoreCallingIdentity(identity);
4274 }
4275 }
4276 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004277 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004278
Svet Ganovb320e182015-04-16 12:30:10 -07004279 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004280 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004281 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004282 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004283 return new String[0];
4284 }
4285
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004286 final long identity = Binder.clearCallingIdentity();
4287 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004288 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004289 } finally {
4290 Binder.restoreCallingIdentity(identity);
4291 }
Wink Saville36469e72014-06-11 15:17:00 -07004292 }
4293
Brad Ebinger51f743a2017-01-23 13:50:20 -08004294 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004295 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4296 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004297 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004298 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004299 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004300
4301 final long identity = Binder.clearCallingIdentity();
4302 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004303 ImsResolver resolver = PhoneFactory.getImsResolver();
4304 if (resolver == null) {
4305 // may happen if the device does not support IMS.
4306 return;
4307 }
4308 resolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004309 } finally {
4310 Binder.restoreCallingIdentity(identity);
4311 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004312 }
4313
4314 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004315 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4316 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004317 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004318 public void disableIms(int slotId) {
4319 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004320
4321 final long identity = Binder.clearCallingIdentity();
4322 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004323 ImsResolver resolver = PhoneFactory.getImsResolver();
4324 if (resolver == null) {
4325 // may happen if the device does not support IMS.
4326 return;
4327 }
4328 resolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004329 } finally {
4330 Binder.restoreCallingIdentity(identity);
4331 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004332 }
4333
4334 /**
4335 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4336 * feature or {@link null} if the service is not available. If the feature is available, the
4337 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4338 */
4339 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004340 IImsServiceFeatureCallback callback) {
4341 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004342
4343 final long identity = Binder.clearCallingIdentity();
4344 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004345 ImsResolver resolver = PhoneFactory.getImsResolver();
4346 if (resolver == null) {
4347 // may happen if the device does not support IMS.
4348 return null;
4349 }
4350 return resolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004351 } finally {
4352 Binder.restoreCallingIdentity(identity);
4353 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004354 }
4355
4356 /**
4357 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4358 * feature during emergency calling or {@link null} if the service is not available. If the
4359 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4360 * listener for feature updates.
4361 */
4362 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4363 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004364
4365 final long identity = Binder.clearCallingIdentity();
4366 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004367 ImsResolver resolver = PhoneFactory.getImsResolver();
4368 if (resolver == null) {
4369 // may happen if the device does not support IMS.
4370 return null;
4371 }
4372 return resolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004373 } finally {
4374 Binder.restoreCallingIdentity(identity);
4375 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004376 }
4377
Brad Ebinger5f64b052017-12-14 14:26:15 -08004378 /**
4379 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004380 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004381 */
4382 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4383 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004384
4385 final long identity = Binder.clearCallingIdentity();
4386 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004387 ImsResolver resolver = PhoneFactory.getImsResolver();
4388 if (resolver == null) {
4389 // may happen if the device does not support IMS.
4390 return null;
4391 }
4392 return resolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004393 } finally {
4394 Binder.restoreCallingIdentity(identity);
4395 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004396 }
4397
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004398 /**
4399 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004400 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004401 */
4402 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4403 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004404
4405 final long identity = Binder.clearCallingIdentity();
4406 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004407 ImsResolver resolver = PhoneFactory.getImsResolver();
4408 if (resolver == null) {
4409 // may happen if the device does not support IMS.
4410 return null;
4411 }
4412 return resolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004413 } finally {
4414 Binder.restoreCallingIdentity(identity);
4415 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004416 }
4417
Brad Ebinger884c07b2018-02-15 16:17:40 -08004418 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004419 * Sets the ImsService Package Name that Telephony will bind to.
4420 *
4421 * @param slotId the slot ID that the ImsService should bind for.
4422 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4423 * ImsService is the device default ImsService.
4424 * @param packageName The package name of the application that contains the ImsService to bind
4425 * to.
4426 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4427 * @hide
4428 */
4429 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004430 int[] subIds = SubscriptionManager.getSubId(slotId);
4431 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4432 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4433 "setImsService");
4434
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004435 final long identity = Binder.clearCallingIdentity();
4436 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004437 ImsResolver resolver = PhoneFactory.getImsResolver();
4438 if (resolver == null) {
4439 // may happen if the device does not support IMS.
4440 return false;
4441 }
4442 return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService,
4443 packageName);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004444 } finally {
4445 Binder.restoreCallingIdentity(identity);
4446 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004447 }
4448
4449 /**
4450 * Return the ImsService configuration.
4451 *
4452 * @param slotId The slot that the ImsService is associated with.
4453 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4454 * the device default.
4455 * @return the package name of the ImsService configuration.
4456 */
4457 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004458 int[] subIds = SubscriptionManager.getSubId(slotId);
4459 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4460 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4461 "getImsService");
4462
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004463 final long identity = Binder.clearCallingIdentity();
4464 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004465 ImsResolver resolver = PhoneFactory.getImsResolver();
4466 if (resolver == null) {
4467 // may happen if the device does not support IMS.
4468 return "";
4469 }
4470 return resolver.getImsServiceConfiguration(slotId, isCarrierImsService);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004471 } finally {
4472 Binder.restoreCallingIdentity(identity);
4473 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004474 }
4475
Wink Saville36469e72014-06-11 15:17:00 -07004476 public void setImsRegistrationState(boolean registered) {
4477 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004478
4479 final long identity = Binder.clearCallingIdentity();
4480 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004481 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004482 } finally {
4483 Binder.restoreCallingIdentity(identity);
4484 }
Wink Saville36469e72014-06-11 15:17:00 -07004485 }
4486
4487 /**
Stuart Scott54788802015-03-30 13:18:01 -07004488 * Set the network selection mode to automatic.
4489 *
4490 */
4491 @Override
4492 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004493 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4494 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004495
Pengquan Menge92a50d2018-09-21 15:54:48 -07004496 if (!isActiveSubscription(subId)) {
4497 return;
4498 }
4499
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004500 final long identity = Binder.clearCallingIdentity();
4501 try {
4502 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4503 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4504 } finally {
4505 Binder.restoreCallingIdentity(identity);
4506 }
Stuart Scott54788802015-03-30 13:18:01 -07004507 }
4508
Pengquan Mengea84e042018-09-20 14:57:26 -07004509 /**
4510 * Ask the radio to connect to the input network and change selection mode to manual.
4511 *
4512 * @param subId the id of the subscription.
4513 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4514 * the operator to attach to.
4515 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4516 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4517 * normal network selection next time.
4518 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004519 */
4520 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004521 public boolean setNetworkSelectionModeManual(
4522 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004523 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4524 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004525
4526 if (!isActiveSubscription(subId)) {
4527 return false;
4528 }
4529
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004530 final long identity = Binder.clearCallingIdentity();
4531 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004532 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004533 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004534 if (DBG) {
4535 log("setNetworkSelectionModeManual: subId: " + subId
4536 + " operator: " + operatorInfo);
4537 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004538 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4539 } finally {
4540 Binder.restoreCallingIdentity(identity);
4541 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004542 }
4543
4544 /**
4545 * Scans for available networks.
4546 */
4547 @Override
Hall Liuf19c44f2018-11-27 14:38:17 -08004548 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004549 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4550 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004551 LocationAccessPolicy.LocationPermissionResult locationResult =
4552 LocationAccessPolicy.checkLocationPermission(mApp,
4553 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4554 .setCallingPackage(callingPackage)
4555 .setCallingPid(Binder.getCallingPid())
4556 .setCallingUid(Binder.getCallingUid())
4557 .setMethod("getCellNetworkScanResults")
4558 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4559 .build());
4560 switch (locationResult) {
4561 case DENIED_HARD:
4562 throw new SecurityException("Not allowed to access scan results -- location");
4563 case DENIED_SOFT:
4564 return null;
4565 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004566
Pengquan Menga1bb6272018-09-06 09:59:22 -07004567 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004568 try {
4569 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004570 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004571 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004572 } finally {
4573 Binder.restoreCallingIdentity(identity);
4574 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004575 }
4576
4577 /**
yinxub1bed742017-04-17 11:45:04 -07004578 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004579 *
yinxub1bed742017-04-17 11:45:04 -07004580 * @param subId id of the subscription
4581 * @param request contains the radio access networks with bands/channels to scan
4582 * @param messenger callback messenger for scan results or errors
4583 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004584 * @return the id of the requested scan which can be used to stop the scan.
4585 */
4586 @Override
4587 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Hall Liuf19c44f2018-11-27 14:38:17 -08004588 IBinder binder, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004589 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4590 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004591 LocationAccessPolicy.LocationPermissionResult locationResult =
4592 LocationAccessPolicy.checkLocationPermission(mApp,
4593 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4594 .setCallingPackage(callingPackage)
4595 .setCallingPid(Binder.getCallingPid())
4596 .setCallingUid(Binder.getCallingUid())
4597 .setMethod("requestNetworkScan")
4598 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4599 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004600 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07004601 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08004602 if (e != null) {
4603 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4604 throw e;
4605 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07004606 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004607 return TelephonyScanManager.INVALID_SCAN_ID;
4608 }
4609 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004610 }
Hall Liu912dfd32019-04-25 14:02:26 -07004611 int callingUid = Binder.getCallingUid();
4612 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07004613 final long identity = Binder.clearCallingIdentity();
4614 try {
4615 return mNetworkScanRequestTracker.startNetworkScan(
4616 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07004617 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07004618 } finally {
4619 Binder.restoreCallingIdentity(identity);
4620 }
yinxu504e1392017-04-12 16:03:22 -07004621 }
4622
Hall Liub2ac8ef2019-02-28 15:56:23 -08004623 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07004624 NetworkScanRequest request, int subId) {
4625 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
4626 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
4627 boolean hasNetworkScanPermission =
4628 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4629 == PERMISSION_GRANTED;
4630
4631 if (!hasCarrierPriv && !hasNetworkScanPermission) {
4632 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
4633 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08004634 }
4635
4636 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4637 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004638 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4639 return new SecurityException("Specific channels must not be"
4640 + " scanned without location access.");
4641 }
4642 }
4643 }
4644
Hall Liub2ac8ef2019-02-28 15:56:23 -08004645 return null;
4646 }
4647
yinxu504e1392017-04-12 16:03:22 -07004648 /**
4649 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004650 *
4651 * @param subId id of the subscription
4652 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004653 */
4654 @Override
4655 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004656 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4657 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004658
Hall Liu912dfd32019-04-25 14:02:26 -07004659 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004660 final long identity = Binder.clearCallingIdentity();
4661 try {
Hall Liu912dfd32019-04-25 14:02:26 -07004662 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004663 } finally {
4664 Binder.restoreCallingIdentity(identity);
4665 }
yinxu504e1392017-04-12 16:03:22 -07004666 }
4667
4668 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004669 * Get the calculated preferred network type.
4670 * Used for debugging incorrect network type.
4671 *
4672 * @return the preferred network type, defined in RILConstants.java.
4673 */
4674 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004675 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004676 final Phone defaultPhone = getDefaultPhone();
4677 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4678 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004679 return RILConstants.PREFERRED_NETWORK_MODE;
4680 }
4681
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004682 final long identity = Binder.clearCallingIdentity();
4683 try {
4684 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004685 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004686 } finally {
4687 Binder.restoreCallingIdentity(identity);
4688 }
Junda Liu84d15a22014-07-02 11:21:04 -07004689 }
4690
4691 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004692 * Get the preferred network type.
4693 * Used for device configuration by some CDMA operators.
4694 *
4695 * @return the preferred network type, defined in RILConstants.java.
4696 */
4697 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004698 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08004699 TelephonyPermissions
4700 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4701 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004702
4703 final long identity = Binder.clearCallingIdentity();
4704 try {
4705 if (DBG) log("getPreferredNetworkType");
4706 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4707 int networkType = (result != null ? result[0] : -1);
4708 if (DBG) log("getPreferredNetworkType: " + networkType);
4709 return networkType;
4710 } finally {
4711 Binder.restoreCallingIdentity(identity);
4712 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004713 }
4714
4715 /**
4716 * Set the preferred network type.
4717 * Used for device configuration by some CDMA operators.
4718 *
4719 * @param networkType the preferred network type, defined in RILConstants.java.
4720 * @return true on success; false on any failure.
4721 */
4722 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004723 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004724 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4725 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004726
4727 final long identity = Binder.clearCallingIdentity();
4728 try {
4729 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4730 Boolean success = (Boolean) sendRequest(
4731 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4732 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4733 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004734 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004735 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4736 }
4737 return success;
4738 } finally {
4739 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004740 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004741 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004742
4743 /**
Miaoa84611c2019-03-15 09:21:10 +08004744 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004745 *
Miaoa84611c2019-03-15 09:21:10 +08004746 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004747 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004748 * @hide
4749 */
4750 @Override
Miaoa84611c2019-03-15 09:21:10 +08004751 public boolean getTetherApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004752 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004753 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08004754 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004755 try {
Miaoa84611c2019-03-15 09:21:10 +08004756 if (phone != null) {
4757 return phone.hasMatchedTetherApnSetting();
4758 } else {
4759 return false;
4760 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004761 } finally {
4762 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004763 }
Junda Liu475951f2014-11-07 16:45:03 -08004764 }
4765
4766 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004767 * Set mobile data enabled
4768 * Used by the user through settings etc to turn on/off mobile data
4769 *
4770 * @param enable {@code true} turn turn data on, else {@code false}
4771 */
4772 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004773 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004774 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4775 mApp, subId, "setUserDataEnabled");
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("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4781 Phone phone = PhoneFactory.getPhone(phoneId);
4782 if (phone != null) {
4783 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08004784 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004785 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004786 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004787 }
4788 } finally {
4789 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004790 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004791 }
4792
4793 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004794 * Get the user enabled state of Mobile Data.
4795 *
4796 * TODO: remove and use isUserDataEnabled.
4797 * This can't be removed now because some vendor codes
4798 * calls through ITelephony directly while they should
4799 * use TelephonyManager.
4800 *
4801 * @return true on enabled
4802 */
4803 @Override
4804 public boolean getDataEnabled(int subId) {
4805 return isUserDataEnabled(subId);
4806 }
4807
4808 /**
4809 * Get whether mobile data is enabled per user setting.
4810 *
4811 * There are other factors deciding whether mobile data is actually enabled, but they are
4812 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004813 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004814 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004815 *
4816 * @return {@code true} if data is enabled else {@code false}
4817 */
4818 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004819 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004820 try {
4821 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4822 null);
4823 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004824 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4825 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004826 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004827
4828 final long identity = Binder.clearCallingIdentity();
4829 try {
4830 int phoneId = mSubscriptionController.getPhoneId(subId);
4831 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4832 Phone phone = PhoneFactory.getPhone(phoneId);
4833 if (phone != null) {
4834 boolean retVal = phone.isUserDataEnabled();
4835 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4836 return retVal;
4837 } else {
4838 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4839 return false;
4840 }
4841 } finally {
4842 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004843 }
4844 }
4845
4846 /**
4847 * Get whether mobile data is enabled.
4848 *
4849 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4850 * whether mobile data is actually enabled.
4851 *
4852 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4853 *
4854 * @return {@code true} if data is enabled else {@code false}
4855 */
4856 @Override
4857 public boolean isDataEnabled(int subId) {
4858 try {
4859 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4860 null);
4861 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004862 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4863 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004864 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004865
4866 final long identity = Binder.clearCallingIdentity();
4867 try {
4868 int phoneId = mSubscriptionController.getPhoneId(subId);
4869 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4870 Phone phone = PhoneFactory.getPhone(phoneId);
4871 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08004872 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004873 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4874 return retVal;
4875 } else {
4876 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4877 return false;
4878 }
4879 } finally {
4880 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004881 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004882 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004883
4884 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004885 public int getCarrierPrivilegeStatus(int subId) {
4886 final Phone phone = getPhone(subId);
4887 if (phone == null) {
4888 loge("getCarrierPrivilegeStatus: Invalid subId");
4889 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4890 }
4891 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004892 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004893 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004894 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4895 }
4896 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004897 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004898 }
Junda Liu29340342014-07-10 15:23:27 -07004899
4900 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004901 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4902 final Phone phone = getPhone(subId);
4903 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09004904 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08004905 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4906 }
4907 UiccProfile profile =
4908 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4909 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09004910 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08004911 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4912 }
4913 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4914 }
4915
4916 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07004917 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
4918 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08004919 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07004920 }
4921
4922 int phoneId = SubscriptionManager.getPhoneId(subId);
4923 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004924 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07004925 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004926 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4927 }
chen xuf7e9fe82019-05-09 19:31:02 -07004928
4929 return card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004930 }
4931
4932 @Override
4933 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004934 if (TextUtils.isEmpty(pkgName))
4935 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004936 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4937 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4938 UiccCard card = UiccController.getInstance().getUiccCard(i);
4939 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004940 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004941 continue;
4942 }
4943
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004944 result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004945 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4946 break;
4947 }
4948 }
4949
4950 return result;
Junda Liu29340342014-07-10 15:23:27 -07004951 }
Derek Tan89e89d42014-07-08 17:00:10 -07004952
4953 @Override
Junda Liue64de782015-04-16 17:19:16 -07004954 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4955 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4956 loge("phoneId " + phoneId + " is not valid.");
4957 return null;
4958 }
4959 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004960 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09004961 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004962 return null ;
4963 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004964 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004965 }
4966
Amith Yamasani6e118872016-02-19 12:53:51 -08004967 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07004968 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004969 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08004970 List<String> privilegedPackages = new ArrayList<>();
4971 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07004972 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
4973 // has UICC in that slot.
4974 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08004975 if (card.hasCarrierPrivilegeRules()) {
4976 if (packages == null) {
4977 // Only check packages in user 0 for now
4978 packages = pm.getInstalledPackagesAsUser(
4979 PackageManager.MATCH_DISABLED_COMPONENTS
chen xuf7e9fe82019-05-09 19:31:02 -07004980 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4981 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08004982 }
4983 for (int p = packages.size() - 1; p >= 0; p--) {
4984 PackageInfo pkgInfo = packages.get(p);
4985 if (pkgInfo != null && pkgInfo.packageName != null
4986 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07004987 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08004988 privilegedPackages.add(pkgInfo.packageName);
4989 }
4990 }
4991 }
4992 }
4993 return privilegedPackages;
4994 }
4995
chen xuf7e9fe82019-05-09 19:31:02 -07004996 @Override
4997 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
4998 List<String> privilegedPackages = new ArrayList<>();
4999 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5000 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5001 }
5002 return privilegedPackages;
5003 }
5004
Wink Savilleb564aae2014-10-23 10:18:09 -07005005 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005006 final Phone phone = getPhone(subId);
5007 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005008 if (card == null) {
5009 loge("getIccId: No UICC");
5010 return null;
5011 }
5012 String iccId = card.getIccId();
5013 if (TextUtils.isEmpty(iccId)) {
5014 loge("getIccId: ICC ID is null or empty.");
5015 return null;
5016 }
5017 return iccId;
5018 }
5019
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005020 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005021 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5022 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005023 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5024 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005025
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005026 final long identity = Binder.clearCallingIdentity();
5027 try {
5028 final String iccId = getIccId(subId);
5029 final Phone phone = getPhone(subId);
5030 if (phone == null) {
5031 return false;
5032 }
5033 final String subscriberId = phone.getSubscriberId();
5034
5035 if (DBG_MERGE) {
5036 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
5037 + subscriberId + " to " + number);
5038 }
5039
5040 if (TextUtils.isEmpty(iccId)) {
5041 return false;
5042 }
5043
5044 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5045
5046 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5047 if (alphaTag == null) {
5048 editor.remove(alphaTagPrefKey);
5049 } else {
5050 editor.putString(alphaTagPrefKey, alphaTag);
5051 }
5052
5053 // Record both the line number and IMSI for this ICCID, since we need to
5054 // track all merged IMSIs based on line number
5055 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5056 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5057 if (number == null) {
5058 editor.remove(numberPrefKey);
5059 editor.remove(subscriberPrefKey);
5060 } else {
5061 editor.putString(numberPrefKey, number);
5062 editor.putString(subscriberPrefKey, subscriberId);
5063 }
5064
5065 editor.commit();
5066 return true;
5067 } finally {
5068 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005069 }
Derek Tan7226c842014-07-02 17:42:23 -07005070 }
5071
5072 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005073 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07005074 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005075 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08005076 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005077 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005078 return null;
5079 }
Derek Tan97ebb422014-09-05 16:55:38 -07005080
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005081 final long identity = Binder.clearCallingIdentity();
5082 try {
5083 String iccId = getIccId(subId);
5084 if (iccId != null) {
5085 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5086 if (DBG_MERGE) {
5087 log("getLine1NumberForDisplay returning "
5088 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5089 }
5090 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005091 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005092 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5093 return null;
5094 } finally {
5095 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005096 }
Derek Tan7226c842014-07-02 17:42:23 -07005097 }
5098
5099 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005100 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005101 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005102 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005103 return null;
5104 }
Derek Tan97ebb422014-09-05 16:55:38 -07005105
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005106 final long identity = Binder.clearCallingIdentity();
5107 try {
5108 String iccId = getIccId(subId);
5109 if (iccId != null) {
5110 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5111 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5112 }
5113 return null;
5114 } finally {
5115 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005116 }
Derek Tan7226c842014-07-02 17:42:23 -07005117 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005118
5119 @Override
Jordan Liub49b04b2019-05-06 14:45:15 -07005120 public String[] getMergedSubscriberIds(int subId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005121 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5122 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005123 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005124 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
5125 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005126 return null;
5127 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005128
Jordan Liub49b04b2019-05-06 14:45:15 -07005129 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5130 // the process, where TelephonyManager was instantiated.
5131 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005132 final long identity = Binder.clearCallingIdentity();
5133 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005134 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005135 final TelephonyManager tele = TelephonyManager.from(context);
5136 final SubscriptionManager sub = SubscriptionManager.from(context);
5137
5138 // Figure out what subscribers are currently active
5139 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005140
Jordan Liub49b04b2019-05-06 14:45:15 -07005141 // Only consider subs which match the current subId
5142 // This logic can be simplified. See b/131189269 for progress.
5143 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005144 activeSubscriberIds.add(tele.getSubscriberId(subId));
5145 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005146
5147 // First pass, find a number override for an active subscriber
5148 String mergeNumber = null;
5149 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5150 for (String key : prefs.keySet()) {
5151 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5152 final String subscriberId = (String) prefs.get(key);
5153 if (activeSubscriberIds.contains(subscriberId)) {
5154 final String iccId = key.substring(
5155 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5156 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5157 mergeNumber = (String) prefs.get(numberKey);
5158 if (DBG_MERGE) {
5159 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5160 + " for active subscriber " + subscriberId);
5161 }
5162 if (!TextUtils.isEmpty(mergeNumber)) {
5163 break;
5164 }
5165 }
5166 }
5167 }
5168
5169 // Shortcut when no active merged subscribers
5170 if (TextUtils.isEmpty(mergeNumber)) {
5171 return null;
5172 }
5173
5174 // Second pass, find all subscribers under that line override
5175 final ArraySet<String> result = new ArraySet<>();
5176 for (String key : prefs.keySet()) {
5177 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5178 final String number = (String) prefs.get(key);
5179 if (mergeNumber.equals(number)) {
5180 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5181 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5182 final String subscriberId = (String) prefs.get(subscriberKey);
5183 if (!TextUtils.isEmpty(subscriberId)) {
5184 result.add(subscriberId);
5185 }
5186 }
5187 }
5188 }
5189
5190 final String[] resultArray = result.toArray(new String[result.size()]);
5191 Arrays.sort(resultArray);
5192 if (DBG_MERGE) {
5193 Slog.d(LOG_TAG,
5194 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5195 }
5196 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005197 } finally {
5198 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005199 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005200 }
5201
5202 @Override
Malcolm Chen6ca97372019-07-01 16:28:21 -07005203 public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) {
5204 enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup");
5205
5206 final long identity = Binder.clearCallingIdentity();
5207 try {
5208 final TelephonyManager telephonyManager = mApp.getSystemService(
5209 TelephonyManager.class);
5210 String subscriberId = telephonyManager.getSubscriberId(subId);
5211 if (subscriberId == null) {
5212 if (DBG) {
5213 log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId "
5214 + subId);
5215 }
5216 return null;
5217 }
5218
5219 final SubscriptionInfo info = SubscriptionController.getInstance()
5220 .getSubscriptionInfo(subId);
5221 final ParcelUuid groupUuid = info.getGroupUuid();
5222 // If it doesn't belong to any group, return just subscriberId of itself.
5223 if (groupUuid == null) {
5224 return new String[]{subscriberId};
5225 }
5226
5227 // Get all subscriberIds from the group.
5228 final List<String> mergedSubscriberIds = new ArrayList<>();
5229 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
5230 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName());
5231 for (SubscriptionInfo subInfo : groupInfos) {
5232 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
5233 if (subscriberId != null) {
5234 mergedSubscriberIds.add(subscriberId);
5235 }
5236 }
5237
5238 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
5239 } finally {
5240 Binder.restoreCallingIdentity(identity);
5241
5242 }
5243 }
5244
5245 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005246 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005247 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5248 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005249
5250 final long identity = Binder.clearCallingIdentity();
5251 try {
5252 final Phone phone = getPhone(subId);
5253 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5254 } finally {
5255 Binder.restoreCallingIdentity(identity);
5256 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005257 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005258
5259 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005260 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005261 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5262 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005263 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005264
5265 final long identity = Binder.clearCallingIdentity();
5266 try {
5267 final Phone phone = getPhone(subId);
5268 if (phone == null) {
5269 return false;
5270 }
5271 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5272 cdmaNonRoamingList);
5273 } finally {
5274 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005275 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005276 }
5277
5278 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005279 @Deprecated
5280 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5281 enforceModifyPermission();
5282
5283 int returnValue = 0;
5284 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005285 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005286 if(result.exception == null) {
5287 if (result.result != null) {
5288 byte[] responseData = (byte[])(result.result);
5289 if(responseData.length > oemResp.length) {
5290 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5291 responseData.length + "bytes. Buffer Size is " +
5292 oemResp.length + "bytes.");
5293 }
5294 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5295 returnValue = responseData.length;
5296 }
5297 } else {
5298 CommandException ex = (CommandException) result.exception;
5299 returnValue = ex.getCommandError().ordinal();
5300 if(returnValue > 0) returnValue *= -1;
5301 }
5302 } catch (RuntimeException e) {
5303 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5304 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5305 if(returnValue > 0) returnValue *= -1;
5306 }
5307
5308 return returnValue;
5309 }
5310
5311 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005312 public void setRadioCapability(RadioAccessFamily[] rafs) {
5313 try {
5314 ProxyController.getInstance().setRadioCapability(rafs);
5315 } catch (RuntimeException e) {
5316 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5317 }
5318 }
5319
5320 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005321 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005322 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005323 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005324 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005325 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005326 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005327 final long identity = Binder.clearCallingIdentity();
5328 try {
chen xub97461a2018-10-26 14:17:57 -07005329 TelephonyPermissions
5330 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5331 mApp, phone.getSubId(), "getRadioAccessFamily");
5332 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005333 } finally {
5334 Binder.restoreCallingIdentity(identity);
5335 }
chen xub97461a2018-10-26 14:17:57 -07005336 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005337 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005338
5339 @Override
5340 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005341 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005342 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005343
5344 final long identity = Binder.clearCallingIdentity();
5345 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005346 ImsManager.getInstance(defaultPhone.getContext(),
5347 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005348 } finally {
5349 Binder.restoreCallingIdentity(identity);
5350 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005351 }
5352
5353 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005354 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005355 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00005356 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005357 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005358 return false;
5359 }
Svet Ganovb320e182015-04-16 12:30:10 -07005360
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005361 final long identity = Binder.clearCallingIdentity();
5362 try {
5363 // Check the user preference and the system-level IMS setting. Even if the user has
5364 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5365 // In the long run, we may instead need to check if there exists a connection service
5366 // which can support video calling.
5367 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005368 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005369 return imsManager.isVtEnabledByPlatform()
5370 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5371 && imsManager.isVtEnabledByUser();
5372 } finally {
5373 Binder.restoreCallingIdentity(identity);
5374 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005375 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005376
Andrew Leea1239f22015-03-02 17:44:07 -08005377 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005378 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
5379 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5380 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5381 return false;
5382 }
5383
5384 final long identity = Binder.clearCallingIdentity();
5385 try {
5386 CarrierConfigManager configManager =
5387 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005388 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005389 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5390 } finally {
5391 Binder.restoreCallingIdentity(identity);
5392 }
Andrew Leea1239f22015-03-02 17:44:07 -08005393 }
5394
5395 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005396 public boolean isWorldPhone(int subId, String callingPackage) {
5397 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5398 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5399 return false;
5400 }
5401
5402 final long identity = Binder.clearCallingIdentity();
5403 try {
5404 CarrierConfigManager configManager =
5405 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005406 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005407 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5408 } finally {
5409 Binder.restoreCallingIdentity(identity);
5410 }
Andrew Leea1239f22015-03-02 17:44:07 -08005411 }
5412
Andrew Lee9431b832015-03-09 18:46:45 -07005413 @Override
5414 public boolean isTtyModeSupported() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005415 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005416 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005417 }
5418
5419 @Override
5420 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005421 final long identity = Binder.clearCallingIdentity();
5422 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005423 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005424 } finally {
5425 Binder.restoreCallingIdentity(identity);
5426 }
Andrew Lee9431b832015-03-09 18:46:45 -07005427 }
5428
Hall Liuf6668912018-10-31 17:05:23 -07005429 /**
5430 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5431 * support for the feature and device firmware support.
5432 *
5433 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5434 */
5435 @Override
5436 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005437 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005438 final Phone phone = getPhone(subscriptionId);
5439 if (phone == null) {
5440 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5441 return false;
5442 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005443 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005444 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005445 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5446 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005447 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005448 return isCarrierSupported && isDeviceSupported;
5449 } finally {
5450 Binder.restoreCallingIdentity(identity);
5451 }
Hall Liu98187582018-01-22 19:15:32 -08005452 }
5453
Hall Liuf6668912018-10-31 17:05:23 -07005454 /**
Hall Liu6a06be62019-07-23 18:39:00 -07005455 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
5456 * RTT setting, will return true if the device and carrier both support RTT.
5457 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07005458 */
5459 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005460 final long identity = Binder.clearCallingIdentity();
5461 try {
Hall Liu6a06be62019-07-23 18:39:00 -07005462 boolean isRttSupported = isRttSupported(subscriptionId);
5463 boolean isUserRttSettingOn = Settings.Secure.getInt(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005464 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Hall Liu6a06be62019-07-23 18:39:00 -07005465 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
5466 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
5467 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005468 } finally {
5469 Binder.restoreCallingIdentity(identity);
5470 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005471 }
5472
Sanket Padawe7310cc72015-01-14 09:53:20 -08005473 /**
5474 * Returns the unique device ID of phone, for example, the IMEI for
5475 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5476 *
5477 * <p>Requires Permission:
5478 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5479 */
5480 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005481 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005482 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005483 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005484 return null;
5485 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005486 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005487 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
5488 callingPackage, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005489 return null;
5490 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005491
5492 final long identity = Binder.clearCallingIdentity();
5493 try {
5494 return phone.getDeviceId();
5495 } finally {
5496 Binder.restoreCallingIdentity(identity);
5497 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005498 }
5499
Ping Sunc67b7c22016-03-02 19:16:45 +08005500 /**
5501 * {@hide}
5502 * Returns the IMS Registration Status on a particular subid
5503 *
5504 * @param subId
5505 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005506 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005507 Phone phone = getPhone(subId);
5508 if (phone != null) {
5509 return phone.isImsRegistered();
5510 } else {
5511 return false;
5512 }
5513 }
5514
Santos Cordon7a1885b2015-02-03 11:15:19 -08005515 @Override
5516 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005517 final long identity = Binder.clearCallingIdentity();
5518 try {
5519 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5520 } finally {
5521 Binder.restoreCallingIdentity(identity);
5522 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005523 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005524
Tyler Gunnf70ed162019-04-03 15:28:53 -07005525 @Override
5526 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5527 final long identity = Binder.clearCallingIdentity();
5528 try {
5529 Phone phone = getPhone(subscriptionId);
5530 if (phone == null) {
5531 return null;
5532 }
5533 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5534 } finally {
5535 Binder.restoreCallingIdentity(identity);
5536 }
5537 }
5538
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005539 /**
5540 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005541 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005542 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005543 final long identity = Binder.clearCallingIdentity();
5544 try {
5545 Phone phone = getPhone(subId);
5546 if (phone != null) {
5547 return phone.isWifiCallingEnabled();
5548 } else {
5549 return false;
5550 }
5551 } finally {
5552 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005553 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005554 }
5555
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005556 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005557 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005558 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005559 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005560 final long identity = Binder.clearCallingIdentity();
5561 try {
5562 Phone phone = getPhone(subId);
5563 if (phone != null) {
5564 return phone.isVideoEnabled();
5565 } else {
5566 return false;
5567 }
5568 } finally {
5569 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005570 }
5571 }
5572
5573 /**
5574 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5575 * defined in {@link ImsRegistrationImplBase}.
5576 */
5577 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005578 final long identity = Binder.clearCallingIdentity();
5579 try {
5580 Phone phone = getPhone(subId);
5581 if (phone != null) {
5582 return phone.getImsRegistrationTech();
5583 } else {
5584 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5585 }
5586 } finally {
5587 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005588 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005589 }
5590
Stuart Scott8eef64f2015-04-08 15:13:54 -07005591 @Override
5592 public void factoryReset(int subId) {
5593 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005594 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5595 return;
5596 }
5597
Svet Ganovcc087f82015-05-12 20:35:54 -07005598 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005599
Svet Ganovcc087f82015-05-12 20:35:54 -07005600 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005601 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5602 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005603 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005604 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005605 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005606 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5607 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005608 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005609 // There has been issues when Sms raw table somehow stores orphan
5610 // fragments. They lead to garbled message when new fragments come
5611 // in and combined with those stale ones. In case this happens again,
5612 // user can reset all network settings which will clean up this table.
5613 cleanUpSmsRawTable(getDefaultPhone().getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07005614 } finally {
5615 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005616 }
5617 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005618
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005619 private void cleanUpSmsRawTable(Context context) {
5620 ContentResolver resolver = context.getContentResolver();
5621 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5622 resolver.delete(uri, null, null);
5623 }
5624
Narayan Kamath1c496c22015-04-16 14:40:19 +01005625 @Override
chen xu5d3637b2019-01-21 23:31:38 -08005626 public String getSimLocaleForSubscriber(int subId) {
5627 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5628 final Phone phone = getPhone(subId);
5629 if (phone == null) {
5630 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08005631 return null;
chen xu5d3637b2019-01-21 23:31:38 -08005632 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005633 final long identity = Binder.clearCallingIdentity();
5634 try {
chen xu5d3637b2019-01-21 23:31:38 -08005635 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5636 phone.getContext().getOpPackageName());
chen xu6291c472019-02-04 12:55:53 -08005637 if (info == null) {
5638 log("getSimLocaleForSubscriber, inactive subId: " + subId);
5639 return null;
5640 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005641 // Try and fetch the locale from the carrier properties or from the SIM language
5642 // preferences (EF-PL and EF-LI)...
5643 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005644 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08005645 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5646 if (localeFromDefaultSim != null) {
5647 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5648 if (DBG) log("Using locale from subId: " + subId + " locale: "
5649 + localeFromDefaultSim);
5650 return localeFromDefaultSim.toLanguageTag();
5651 } else {
5652 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005653 }
5654 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005655
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005656 // The SIM language preferences only store a language (e.g. fr = French), not an
5657 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5658 // the SIM and carrier preferences does not include a country we add the country
5659 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005660 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005661 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08005662 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005663 return mccLocale.toLanguageTag();
5664 }
5665
5666 if (DBG) log("No locale found - returning null");
5667 return null;
5668 } finally {
5669 Binder.restoreCallingIdentity(identity);
5670 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005671 }
5672
5673 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005674 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005675 }
5676
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005677 /**
5678 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5679 */
5680 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005681 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005682 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005683
Chenjie Yu1ba97252018-01-11 18:16:20 -08005684 private final ModemActivityInfo mLastModemActivityInfo =
5685 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
5686
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005687 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005688 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5689 * representing the state of the modem.
5690 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005691 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5692 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005693 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005694 */
5695 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005696 public void requestModemActivityInfo(ResultReceiver result) {
5697 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005698 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005699
5700 final long identity = Binder.clearCallingIdentity();
5701 try {
5702 ModemActivityInfo ret = null;
5703 synchronized (mLastModemActivityInfo) {
5704 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5705 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07005706 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07005707 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005708 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
5709 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005710 mergedTxTimeMs[i] = info.getTxTimeMillis()[i]
5711 + mLastModemActivityInfo.getTxTimeMillis()[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005712 }
5713 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005714 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
5715 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005716 mLastModemActivityInfo.setIdleTimeMillis(
5717 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
5718 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
5719 mLastModemActivityInfo.setRxTimeMillis(
5720 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
5721 mLastModemActivityInfo.setEnergyUsed(
5722 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005723 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005724 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
5725 mLastModemActivityInfo.getSleepTimeMillis(),
5726 mLastModemActivityInfo.getIdleTimeMillis(),
5727 mLastModemActivityInfo.getTxTimeMillis(),
5728 mLastModemActivityInfo.getRxTimeMillis(),
5729 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005730 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005731 Bundle bundle = new Bundle();
5732 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
5733 result.send(0, bundle);
5734 } finally {
5735 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005736 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005737 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005738
Siddharth Rayb8114062018-06-17 15:02:38 -07005739 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
5740 // less than total activity duration.
5741 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
5742 if (info == null) {
5743 return false;
5744 }
5745 int activityDurationMs =
5746 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
5747 int totalTxTimeMs = 0;
5748 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
5749 totalTxTimeMs += info.getTxTimeMillis()[i];
5750 }
5751 return (info.isValid()
5752 && (info.getSleepTimeMillis() <= activityDurationMs)
5753 && (info.getIdleTimeMillis() <= activityDurationMs)
5754 && (info.getRxTimeMillis() <= activityDurationMs)
5755 && (totalTxTimeMs <= activityDurationMs));
5756 }
5757
Jack Yu85bd38a2015-11-09 11:34:32 -08005758 /**
5759 * {@hide}
5760 * Returns the service state information on specified subscription.
5761 */
5762 @Override
5763 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005764 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005765 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08005766 return null;
5767 }
5768
Hall Liuf19c44f2018-11-27 14:38:17 -08005769 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
5770 LocationAccessPolicy.checkLocationPermission(mApp,
5771 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5772 .setCallingPackage(callingPackage)
5773 .setCallingPid(Binder.getCallingPid())
5774 .setCallingUid(Binder.getCallingUid())
5775 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07005776 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005777 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5778 .build());
5779
5780 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
5781 LocationAccessPolicy.checkLocationPermission(mApp,
5782 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5783 .setCallingPackage(callingPackage)
5784 .setCallingPid(Binder.getCallingPid())
5785 .setCallingUid(Binder.getCallingUid())
5786 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07005787 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005788 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5789 .build());
5790 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
5791 boolean hasFinePermission =
5792 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5793 boolean hasCoarsePermission =
5794 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5795
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005796 final long identity = Binder.clearCallingIdentity();
5797 try {
5798 final Phone phone = getPhone(subId);
5799 if (phone == null) {
5800 return null;
5801 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005802
Hall Liuf19c44f2018-11-27 14:38:17 -08005803 ServiceState ss = phone.getServiceState();
5804
5805 // Scrub out the location info in ServiceState depending on what level of access
5806 // the caller has.
5807 if (hasFinePermission) return ss;
5808 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
5809 return ss.sanitizeLocationInfo(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005810 } finally {
5811 Binder.restoreCallingIdentity(identity);
5812 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005813 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005814
5815 /**
5816 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
5817 *
5818 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5819 * voicemail ringtone.
5820 * @return The URI for the ringtone to play when receiving a voicemail from a specific
5821 * PhoneAccount.
5822 */
5823 @Override
5824 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005825 final long identity = Binder.clearCallingIdentity();
5826 try {
5827 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5828 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005829 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005830 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005831
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005832 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
5833 } finally {
5834 Binder.restoreCallingIdentity(identity);
5835 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005836 }
5837
5838 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005839 * Sets the per-account voicemail ringtone.
5840 *
5841 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5842 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5843 *
5844 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5845 * voicemail ringtone.
5846 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5847 * PhoneAccount.
5848 */
5849 @Override
5850 public void setVoicemailRingtoneUri(String callingPackage,
5851 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005852 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005853 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5854 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005855 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005856 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5857 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5858 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005859 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005860
5861 final long identity = Binder.clearCallingIdentity();
5862 try {
5863 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5864 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005865 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005866 }
5867 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5868 } finally {
5869 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005870 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005871 }
5872
5873 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005874 * Returns whether vibration is set for voicemail notification in Phone settings.
5875 *
5876 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5877 * voicemail vibration setting.
5878 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5879 */
5880 @Override
5881 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005882 final long identity = Binder.clearCallingIdentity();
5883 try {
5884 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5885 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005886 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005887 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005888
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005889 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5890 } finally {
5891 Binder.restoreCallingIdentity(identity);
5892 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005893 }
5894
Youhan Wange64578a2016-05-02 15:32:42 -07005895 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005896 * Sets the per-account voicemail vibration.
5897 *
5898 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5899 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5900 *
5901 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5902 * voicemail vibration setting.
5903 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5904 * specific PhoneAccount.
5905 */
5906 @Override
5907 public void setVoicemailVibrationEnabled(String callingPackage,
5908 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005909 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005910 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5911 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005912 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005913 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5914 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5915 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005916 }
5917
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005918 final long identity = Binder.clearCallingIdentity();
5919 try {
5920 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5921 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005922 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005923 }
5924 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5925 } finally {
5926 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005927 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005928 }
5929
5930 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005931 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5932 *
5933 * @throws SecurityException if the caller does not have the required permission
5934 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005935 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005936 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07005937 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005938 }
5939
5940 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005941 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5942 * permission.
5943 *
5944 * @throws SecurityException if the caller does not have the required permission
5945 */
5946 private void enforceSendSmsPermission() {
5947 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5948 }
5949
5950 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005951 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005952 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005953 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005954 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005955 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005956 final long identity = Binder.clearCallingIdentity();
5957 try {
5958 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005959 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005960 if (componentName == null) {
5961 throw new SecurityException(
5962 "Caller not current active visual voicemail package[null]");
5963 }
5964 String vvmPackage = componentName.getPackageName();
5965 if (!callingPackage.equals(vvmPackage)) {
5966 throw new SecurityException("Caller not current active visual voicemail package["
5967 + vvmPackage + "]");
5968 }
5969 } finally {
5970 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005971 }
5972 }
5973
5974 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005975 * Return the application ID for the app type.
5976 *
5977 * @param subId the subscription ID that this request applies to.
5978 * @param appType the uicc app type.
5979 * @return Application ID for specificied app type, or null if no uicc.
5980 */
5981 @Override
5982 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005983 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005984 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005985
5986 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005987 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005988 if (phone == null) {
5989 return null;
5990 }
5991 String aid = null;
5992 try {
5993 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5994 .getApplicationByType(appType).getAid();
5995 } catch (Exception e) {
5996 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5997 }
5998 return aid;
5999 } finally {
6000 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006001 }
Youhan Wange64578a2016-05-02 15:32:42 -07006002 }
6003
Youhan Wang4001d252016-05-11 10:29:41 -07006004 /**
6005 * Return the Electronic Serial Number.
6006 *
6007 * @param subId the subscription ID that this request applies to.
6008 * @return ESN or null if error.
6009 */
6010 @Override
6011 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006012 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006013 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006014
6015 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006016 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006017 if (phone == null) {
6018 return null;
6019 }
6020 String esn = null;
6021 try {
6022 esn = phone.getEsn();
6023 } catch (Exception e) {
6024 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6025 }
6026 return esn;
6027 } finally {
6028 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006029 }
Youhan Wang4001d252016-05-11 10:29:41 -07006030 }
6031
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006032 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006033 * Return the Preferred Roaming List Version.
6034 *
6035 * @param subId the subscription ID that this request applies to.
6036 * @return PRLVersion or null if error.
6037 */
6038 @Override
6039 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006040 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006041 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006042
6043 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006044 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006045 if (phone == null) {
6046 return null;
6047 }
6048 String cdmaPrlVersion = null;
6049 try {
6050 cdmaPrlVersion = phone.getCdmaPrlVersion();
6051 } catch (Exception e) {
6052 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6053 }
6054 return cdmaPrlVersion;
6055 } finally {
6056 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006057 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006058 }
6059
6060 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006061 * Get snapshot of Telephony histograms
6062 * @return List of Telephony histograms
6063 * @hide
6064 */
6065 @Override
6066 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006067 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6068 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006069
6070 final long identity = Binder.clearCallingIdentity();
6071 try {
6072 return RIL.getTelephonyRILTimingHistograms();
6073 } finally {
6074 Binder.restoreCallingIdentity(identity);
6075 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006076 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006077
6078 /**
6079 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006080 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6081 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006082 * Require system privileges. In the future we may add this to carrier APIs.
6083 *
Michele Berionne482f8202018-11-27 18:57:59 -08006084 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006085 */
6086 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006087 @TelephonyManager.SetCarrierRestrictionResult
6088 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006089 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006090 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006091
Michele Berionne482f8202018-11-27 18:57:59 -08006092 if (carrierRestrictionRules == null) {
6093 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08006094 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006095
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006096 final long identity = Binder.clearCallingIdentity();
6097 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006098 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07006099 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006100 } finally {
6101 Binder.restoreCallingIdentity(identity);
6102 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006103 }
6104
6105 /**
6106 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006107 * Get the allowed carrier list and the excluded carrier list, including the priority between
6108 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006109 * Require system privileges. In the future we may add this to carrier APIs.
6110 *
Michele Berionne482f8202018-11-27 18:57:59 -08006111 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07006112 */
6113 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006114 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006115 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07006116 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006117
6118 final long identity = Binder.clearCallingIdentity();
6119 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006120 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
6121 if (response instanceof CarrierRestrictionRules) {
6122 return (CarrierRestrictionRules) response;
6123 }
6124 // Response is an Exception of some kind,
6125 // which is signalled to the user as a NULL retval
6126 return null;
6127 } catch (Exception e) {
6128 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
6129 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006130 } finally {
6131 Binder.restoreCallingIdentity(identity);
6132 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006133 }
6134
fionaxu59545b42016-05-25 15:53:37 -07006135 /**
6136 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
6137 * @param subId the subscription ID that this action applies to.
6138 * @param enabled control enable or disable metered apns.
6139 * {@hide}
6140 */
6141 @Override
6142 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
6143 enforceModifyPermission();
6144 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006145
6146 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006147 if (phone == null) {
6148 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
6149 return;
6150 }
6151 try {
6152 phone.carrierActionSetMeteredApnsEnabled(enabled);
6153 } catch (Exception e) {
6154 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006155 } finally {
6156 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006157 }
6158 }
6159
6160 /**
6161 * Action set from carrier signalling broadcast receivers to enable/disable radio
6162 * @param subId the subscription ID that this action applies to.
6163 * @param enabled control enable or disable radio.
6164 * {@hide}
6165 */
6166 @Override
6167 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
6168 enforceModifyPermission();
6169 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006170
6171 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006172 if (phone == null) {
6173 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
6174 return;
6175 }
6176 try {
6177 phone.carrierActionSetRadioEnabled(enabled);
6178 } catch (Exception e) {
6179 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006180 } finally {
6181 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006182 }
6183 }
6184
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006185 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006186 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6187 * network status based on which carrier apps could apply actions accordingly,
6188 * enable/disable default url handler for example.
6189 *
6190 * @param subId the subscription ID that this action applies to.
6191 * @param report control start/stop reporting the default network status.
6192 * {@hide}
6193 */
6194 @Override
6195 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6196 enforceModifyPermission();
6197 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006198
6199 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006200 if (phone == null) {
6201 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6202 return;
6203 }
6204 try {
6205 phone.carrierActionReportDefaultNetworkStatus(report);
6206 } catch (Exception e) {
6207 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006208 } finally {
6209 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006210 }
6211 }
6212
6213 /**
fionaxud9622282017-07-17 17:51:30 -07006214 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6215 * @param subId the subscription ID that this action applies to.
6216 * {@hide}
6217 */
6218 @Override
6219 public void carrierActionResetAll(int subId) {
6220 enforceModifyPermission();
6221 final Phone phone = getPhone(subId);
6222 if (phone == null) {
6223 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6224 return;
6225 }
6226 try {
6227 phone.carrierActionResetAll();
6228 } catch (Exception e) {
6229 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6230 }
6231 }
6232
6233 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006234 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6235 * bug report is being generated.
6236 */
6237 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006238 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006239 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6240 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006241 writer.println("Permission Denial: can't dump Phone from pid="
6242 + Binder.getCallingPid()
6243 + ", uid=" + Binder.getCallingUid()
6244 + "without permission "
6245 + android.Manifest.permission.DUMP);
6246 return;
6247 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006248 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006249 }
Jack Yueb89b242016-06-22 13:27:47 -07006250
Brad Ebingerdac2f002018-04-03 15:17:52 -07006251 @Override
6252 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6253 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6254 throws RemoteException {
6255 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
6256 }
6257
Jack Yueb89b242016-06-22 13:27:47 -07006258 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006259 * Get aggregated video call data usage since boot.
6260 *
6261 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6262 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006263 * {@hide}
6264 */
6265 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006266 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006267 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6268 null);
6269
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006270 final long identity = Binder.clearCallingIdentity();
6271 try {
6272 // NetworkStatsService keeps tracking the active network interface and identity. It
6273 // records the delta with the corresponding network identity.
6274 // We just return the total video call data usage snapshot since boot.
6275 Phone phone = getPhone(subId);
6276 if (phone != null) {
6277 return phone.getVtDataUsage(perUidStats);
6278 }
6279 return null;
6280 } finally {
6281 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006282 }
Jack Yueb89b242016-06-22 13:27:47 -07006283 }
Jack Yu75ab2952016-07-08 14:29:33 -07006284
6285 /**
6286 * Policy control of data connection. Usually used when data limit is passed.
6287 * @param enabled True if enabling the data, otherwise disabling.
6288 * @param subId Subscription index
6289 * {@hide}
6290 */
6291 @Override
6292 public void setPolicyDataEnabled(boolean enabled, int subId) {
6293 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006294
6295 final long identity = Binder.clearCallingIdentity();
6296 try {
6297 Phone phone = getPhone(subId);
6298 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006299 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006300 }
6301 } finally {
6302 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006303 }
6304 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006305
6306 /**
6307 * Get Client request stats
6308 * @return List of Client Request Stats
6309 * @hide
6310 */
6311 @Override
6312 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006313 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006314 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006315 return null;
6316 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006317 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006318
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006319 final long identity = Binder.clearCallingIdentity();
6320 try {
6321 if (phone != null) {
6322 return phone.getClientRequestStats();
6323 }
6324
6325 return null;
6326 } finally {
6327 Binder.restoreCallingIdentity(identity);
6328 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006329 }
6330
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006331 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006332 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006333 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006334 }
Jack Yueb4124c2017-02-16 15:32:43 -08006335
6336 /**
Grace Chen70990072017-03-24 17:21:30 -07006337 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006338 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006339 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006340 * @param state State of SIM (power down, power up, pass through)
6341 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6342 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6343 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006344 *
6345 **/
6346 @Override
Grace Chen70990072017-03-24 17:21:30 -07006347 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006348 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006349 Phone phone = PhoneFactory.getPhone(slotIndex);
6350
vagdeviaf9a5b92018-08-15 16:01:53 -07006351 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6352
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006353 final long identity = Binder.clearCallingIdentity();
6354 try {
6355 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006356 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006357 }
6358 } finally {
6359 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006360 }
6361 }
Shuo Qiandd210312017-04-12 22:11:33 +00006362
Tyler Gunn65d45c22017-06-05 11:22:26 -07006363 private boolean isUssdApiAllowed(int subId) {
6364 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006365 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006366 if (configManager == null) {
6367 return false;
6368 }
6369 PersistableBundle pb = configManager.getConfigForSubId(subId);
6370 if (pb == null) {
6371 return false;
6372 }
6373 return pb.getBoolean(
6374 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6375 }
6376
Shuo Qiandd210312017-04-12 22:11:33 +00006377 /**
6378 * Check if phone is in emergency callback mode
6379 * @return true if phone is in emergency callback mode
6380 * @param subId sub id
6381 */
goneil9c5f4872017-12-05 14:07:56 -08006382 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006383 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006384 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006385 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006386
6387 final long identity = Binder.clearCallingIdentity();
6388 try {
6389 if (phone != null) {
6390 return phone.isInEcm();
6391 } else {
6392 return false;
6393 }
6394 } finally {
6395 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006396 }
6397 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006398
6399 /**
6400 * Get the current signal strength information for the given subscription.
6401 * Because this information is not updated when the device is in a low power state
6402 * it should not be relied-upon to be current.
6403 * @param subId Subscription index
6404 * @return the most recent cached signal strength info from the modem
6405 */
6406 @Override
6407 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006408 final long identity = Binder.clearCallingIdentity();
6409 try {
6410 Phone p = getPhone(subId);
6411 if (p == null) {
6412 return null;
6413 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006414
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006415 return p.getSignalStrength();
6416 } finally {
6417 Binder.restoreCallingIdentity(identity);
6418 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006419 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006420
Pengquan Meng77b7f132018-08-22 14:49:57 -07006421 /**
Chen Xuf792fd62018-10-17 17:54:36 +00006422 * Get the current modem radio state for the given slot.
6423 * @param slotIndex slot index.
6424 * @param callingPackage the name of the package making the call.
6425 * @return the current radio power state from the modem
6426 */
6427 @Override
6428 public int getRadioPowerState(int slotIndex, String callingPackage) {
6429 Phone phone = PhoneFactory.getPhone(slotIndex);
6430 if (phone != null) {
6431 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6432 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
6433 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6434 }
6435
6436 final long identity = Binder.clearCallingIdentity();
6437 try {
6438 return phone.getRadioPowerState();
6439 } finally {
6440 Binder.restoreCallingIdentity(identity);
6441 }
6442 }
6443 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6444 }
6445
6446 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07006447 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6448 *
6449 * <p>Requires one of the following permissions:
6450 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6451 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6452 * privileges.
6453 *
6454 * @param subId subscription id
6455 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6456 * {@code false}.
6457 */
6458 @Override
6459 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006460 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6461 null /* message */);
6462
Pengquan Menga1bb6272018-09-06 09:59:22 -07006463 boolean isEnabled = false;
6464 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07006465 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006466 Phone phone = getPhone(subId);
6467 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006468 } catch (Exception e) {
6469 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6470 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07006471 } finally {
6472 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006473 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006474 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006475 }
6476
6477
6478 /**
6479 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6480 *
6481 * <p> Requires permission:
6482 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6483 * privileges.
6484 *
6485 * @param subId subscription id
6486 * @param isEnabled {@code true} means enable, {@code false} means disable.
6487 */
6488 @Override
6489 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006490 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6491 mApp, subId, "setDataRoamingEnabled");
6492
Pengquan Menga1bb6272018-09-06 09:59:22 -07006493 final long identity = Binder.clearCallingIdentity();
6494 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006495 Phone phone = getPhone(subId);
6496 if (phone != null) {
6497 phone.setDataRoamingEnabled(isEnabled);
6498 }
6499 } finally {
6500 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006501 }
6502 }
6503
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006504 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006505 public boolean isManualNetworkSelectionAllowed(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006506 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6507 mApp, subId, "isManualNetworkSelectionAllowed");
6508
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006509 boolean isAllowed = true;
6510 final long identity = Binder.clearCallingIdentity();
6511 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006512 Phone phone = getPhone(subId);
6513 if (phone != null) {
6514 isAllowed = phone.isCspPlmnEnabled();
6515 }
6516 } finally {
6517 Binder.restoreCallingIdentity(identity);
6518 }
6519 return isAllowed;
6520 }
6521
6522 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006523 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006524 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08006525 try {
6526 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07006527 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08006528 } catch (SecurityException e) {
6529 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6530 // has carrier privileges on an active UICC
6531 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6532 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006533 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08006534 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006535 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006536
6537 final long identity = Binder.clearCallingIdentity();
6538 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006539 UiccController uiccController = UiccController.getInstance();
6540 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07006541 if (hasReadPermission) {
6542 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006543 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07006544
6545 // Remove private info if the caller doesn't have access
6546 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6547 for (UiccCardInfo cardInfo : cardInfos) {
6548 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6549 // is available
6550 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
6551 if (card == null || card.getUiccProfile() == null) {
6552 // assume no access if the card or profile is unavailable
6553 filteredInfos.add(cardInfo.getUnprivileged());
6554 continue;
6555 }
6556 UiccProfile profile = card.getUiccProfile();
6557 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6558 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6559 filteredInfos.add(cardInfo);
6560 } else {
6561 filteredInfos.add(cardInfo.getUnprivileged());
6562 }
6563 }
6564 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08006565 } finally {
6566 Binder.restoreCallingIdentity(identity);
6567 }
6568 }
6569
6570 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006571 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006572 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006573
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006574 final long identity = Binder.clearCallingIdentity();
6575 try {
6576 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6577 if (slots == null) {
6578 Rlog.i(LOG_TAG, "slots is null.");
6579 return null;
6580 }
6581
6582 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6583 for (int i = 0; i < slots.length; i++) {
6584 UiccSlot slot = slots[i];
6585 if (slot == null) {
6586 continue;
6587 }
6588
Jordan Liu7be7e652019-05-06 18:55:02 +00006589 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006590 UiccCard card = slot.getUiccCard();
6591 if (card != null) {
6592 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00006593 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07006594 cardId = slot.getEid();
6595 if (TextUtils.isEmpty(cardId)) {
6596 cardId = slot.getIccId();
6597 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006598 }
6599
Jordan Liu857451f2019-05-09 16:35:35 -07006600 if (cardId != null) {
6601 // if cardId is an ICCID, strip off trailing Fs before exposing to user
6602 // if cardId is an EID, it's all digits so this is fine
6603 cardId = IccUtils.stripTrailingFs(cardId);
6604 }
6605
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006606 int cardState = 0;
6607 switch (slot.getCardState()) {
6608 case CARDSTATE_ABSENT:
6609 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6610 break;
6611 case CARDSTATE_PRESENT:
6612 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6613 break;
6614 case CARDSTATE_ERROR:
6615 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6616 break;
6617 case CARDSTATE_RESTRICTED:
6618 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6619 break;
6620 default:
6621 break;
6622
6623 }
6624
6625 infos[i] = new UiccSlotInfo(
6626 slot.isActive(),
6627 slot.isEuicc(),
6628 cardId,
6629 cardState,
6630 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08006631 slot.isExtendedApduSupported(),
6632 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006633 }
6634 return infos;
6635 } finally {
6636 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006637 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006638 }
6639
6640 @Override
6641 public boolean switchSlots(int[] physicalSlots) {
6642 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006643
6644 final long identity = Binder.clearCallingIdentity();
6645 try {
6646 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6647 } finally {
6648 Binder.restoreCallingIdentity(identity);
6649 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006650 }
Jack Yu4c988042018-02-27 15:30:01 -08006651
6652 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006653 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006654 final long identity = Binder.clearCallingIdentity();
6655 try {
6656 return UiccController.getInstance().getCardIdForDefaultEuicc();
6657 } finally {
6658 Binder.restoreCallingIdentity(identity);
6659 }
6660 }
6661
6662 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006663 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6664 enforceModifyPermission();
6665 final Phone phone = getPhone(subId);
6666 if (phone == null) {
6667 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6668 return;
6669 }
6670
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006671 final long identity = Binder.clearCallingIdentity();
6672 try {
6673 phone.setRadioIndicationUpdateMode(filters, mode);
6674 } finally {
6675 Binder.restoreCallingIdentity(identity);
6676 }
Jack Yu4c988042018-02-27 15:30:01 -08006677 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006678
6679 /**
goneil47ffb6e2018-04-06 15:40:58 -07006680 * A test API to reload the UICC profile.
6681 *
6682 * <p>Requires that the calling app has permission
6683 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6684 * @hide
6685 */
6686 @Override
6687 public void refreshUiccProfile(int subId) {
6688 enforceModifyPermission();
6689
6690 final long identity = Binder.clearCallingIdentity();
6691 try {
6692 Phone phone = getPhone(subId);
6693 if (phone == null) {
6694 return;
6695 }
6696 UiccCard uiccCard = phone.getUiccCard();
6697 if (uiccCard == null) {
6698 return;
6699 }
6700 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6701 if (uiccProfile == null) {
6702 return;
6703 }
6704 uiccProfile.refresh();
6705 } finally {
6706 Binder.restoreCallingIdentity(identity);
6707 }
6708 }
6709
6710 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006711 * Returns false if the mobile data is disabled by default, otherwise return true.
6712 */
6713 private boolean getDefaultDataEnabled() {
6714 return "true".equalsIgnoreCase(
6715 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
6716 }
6717
6718 /**
6719 * Returns true if the data roaming is enabled by default, i.e the system property
6720 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
6721 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
6722 */
6723 private boolean getDefaultDataRoamingEnabled(int subId) {
6724 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006725 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006726 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
6727 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
6728 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
6729 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
6730 return isDataRoamingEnabled;
6731 }
6732
6733 /**
6734 * Returns the default network type for the given {@code subId}, if the default network type is
6735 * not set, return {@link Phone#PREFERRED_NT_MODE}.
6736 */
6737 private int getDefaultNetworkType(int subId) {
6738 return Integer.parseInt(
6739 TelephonyManager.getTelephonyProperty(
6740 mSubscriptionController.getPhoneId(subId),
6741 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
6742 String.valueOf(Phone.PREFERRED_NT_MODE)));
6743 }
fionaxua13278b2018-03-21 00:08:13 -07006744
6745 @Override
6746 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07006747 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07006748 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006749
6750 final long identity = Binder.clearCallingIdentity();
6751 try {
6752 final Phone phone = getPhone(subId);
6753 if (phone == null) {
6754 loge("setCarrierTestOverride fails with invalid subId: " + subId);
6755 return;
6756 }
chen xueaba88a2019-03-15 13:15:10 -07006757 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
6758 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006759 } finally {
6760 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006761 }
fionaxua13278b2018-03-21 00:08:13 -07006762 }
6763
6764 @Override
6765 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006766 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006767
6768 final long identity = Binder.clearCallingIdentity();
6769 try {
6770 final Phone phone = getPhone(subId);
6771 if (phone == null) {
6772 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
6773 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
6774 }
6775 return phone.getCarrierIdListVersion();
6776 } finally {
6777 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006778 }
fionaxua13278b2018-03-21 00:08:13 -07006779 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07006780
6781 @Override
6782 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
6783 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6784 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
6785 return -1;
6786 }
6787
6788 final long identity = Binder.clearCallingIdentity();
6789 try {
6790 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
6791 } finally {
6792 Binder.restoreCallingIdentity(identity);
6793 }
6794 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006795
6796 @Override
6797 public int getCdmaRoamingMode(int subId) {
6798 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6799 mApp, subId, "getCdmaRoamingMode");
6800
6801 final long identity = Binder.clearCallingIdentity();
6802 try {
6803 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
6804 } finally {
6805 Binder.restoreCallingIdentity(identity);
6806 }
6807 }
6808
6809 @Override
6810 public boolean setCdmaRoamingMode(int subId, int mode) {
6811 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6812 mApp, subId, "setCdmaRoamingMode");
6813
6814 final long identity = Binder.clearCallingIdentity();
6815 try {
6816 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
6817 } finally {
6818 Binder.restoreCallingIdentity(identity);
6819 }
6820 }
6821
6822 @Override
6823 public boolean setCdmaSubscriptionMode(int subId, int mode) {
6824 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6825 mApp, subId, "setCdmaSubscriptionMode");
6826
6827 final long identity = Binder.clearCallingIdentity();
6828 try {
6829 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
6830 } finally {
6831 Binder.restoreCallingIdentity(identity);
6832 }
6833 }
Makoto Onukida3bf792018-09-18 16:06:29 -07006834
6835 private void ensureUserRunning(int userId) {
6836 if (!mUserManager.isUserRunning(userId)) {
6837 throw new IllegalStateException("User " + userId + " does not exist or not running");
6838 }
6839 }
6840
6841 /**
6842 * Returns a list of SMS apps on a given user.
6843 *
6844 * Only the shell user (UID 2000 or 0) can call it.
6845 * Target user must be running.
6846 */
6847 @Override
6848 public String[] getSmsApps(int userId) {
6849 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
6850 ensureUserRunning(userId);
6851
6852 final Collection<SmsApplicationData> apps =
6853 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
6854
6855 String[] ret = new String[apps.size()];
6856 int i = 0;
6857 for (SmsApplicationData app : apps) {
6858 ret[i++] = app.mPackageName;
6859 }
6860 return ret;
6861 }
6862
6863 /**
6864 * Returns the default SMS app package name on a given user.
6865 *
6866 * Only the shell user (UID 2000 or 0) can call it.
6867 * Target user must be running.
6868 */
6869 @Override
6870 public String getDefaultSmsApp(int userId) {
6871 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
6872 ensureUserRunning(userId);
6873
6874 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
6875 /* updateIfNeeded= */ true, userId);
6876 return cn == null ? null : cn.getPackageName();
6877 }
6878
6879 /**
6880 * Set a package as the default SMS app on a given user.
6881 *
6882 * Only the shell user (UID 2000 or 0) can call it.
6883 * Target user must be running.
6884 */
6885 @Override
6886 public void setDefaultSmsApp(int userId, String packageName) {
6887 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
6888 ensureUserRunning(userId);
6889
6890 boolean found = false;
6891 for (String pkg : getSmsApps(userId)) {
6892 if (TextUtils.equals(packageName, pkg)) {
6893 found = true;
6894 break;
6895 }
6896 }
6897 if (!found) {
6898 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
6899 }
6900
6901 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
6902 }
sqianc5eccab2018-10-19 18:46:41 -07006903
6904 @Override
sqian8c685422019-02-22 15:55:18 -08006905 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
sqianc5eccab2018-10-19 18:46:41 -07006906 String callingPackage) {
sqian11b7a0e2018-12-05 18:48:28 -08006907 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
sqian8c685422019-02-22 15:55:18 -08006908 mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08006909 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6910 }
6911 final long identity = Binder.clearCallingIdentity();
6912 try {
sqian854d44b2018-12-12 16:48:18 -08006913 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
6914 for (Phone phone: PhoneFactory.getPhones()) {
6915 if (phone.getEmergencyNumberTracker() != null
6916 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
6917 emergencyNumberListInternal.put(
6918 phone.getSubId(),
6919 phone.getEmergencyNumberTracker().getEmergencyNumberList());
6920 }
sqian11b7a0e2018-12-05 18:48:28 -08006921 }
sqian854d44b2018-12-12 16:48:18 -08006922 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08006923 } finally {
6924 Binder.restoreCallingIdentity(identity);
6925 }
sqianc5eccab2018-10-19 18:46:41 -07006926 }
6927
6928 @Override
sqian8c685422019-02-22 15:55:18 -08006929 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006930 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08006931 if (!exactMatch) {
6932 TelephonyPermissions
6933 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08006934 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08006935 }
6936 final long identity = Binder.clearCallingIdentity();
6937 try {
sqian854d44b2018-12-12 16:48:18 -08006938 for (Phone phone: PhoneFactory.getPhones()) {
6939 if (phone.getEmergencyNumberTracker() != null
6940 && phone.getEmergencyNumberTracker() != null) {
6941 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
6942 number, exactMatch)) {
6943 return true;
sqian11b7a0e2018-12-05 18:48:28 -08006944 }
6945 }
sqian11b7a0e2018-12-05 18:48:28 -08006946 }
6947 return false;
6948 } finally {
6949 Binder.restoreCallingIdentity(identity);
6950 }
6951 }
6952
sqianf4ca7ed2019-01-15 18:32:07 -08006953 /**
6954 * Update emergency number list for test mode.
6955 */
6956 @Override
6957 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
6958 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6959 "updateEmergencyNumberListTestMode");
6960
6961 final long identity = Binder.clearCallingIdentity();
6962 try {
6963 for (Phone phone: PhoneFactory.getPhones()) {
6964 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6965 if (tracker != null) {
6966 tracker.executeEmergencyNumberTestModeCommand(action, num);
6967 }
6968 }
6969 } finally {
6970 Binder.restoreCallingIdentity(identity);
6971 }
6972 }
6973
6974 /**
6975 * Get the full emergency number list for test mode.
6976 */
6977 @Override
6978 public List<String> getEmergencyNumberListTestMode() {
6979 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6980 "getEmergencyNumberListTestMode");
6981
6982 final long identity = Binder.clearCallingIdentity();
6983 try {
6984 Set<String> emergencyNumbers = new HashSet<>();
6985 for (Phone phone: PhoneFactory.getPhones()) {
6986 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6987 if (tracker != null) {
6988 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
6989 emergencyNumbers.add(num.getNumber());
6990 }
6991 }
6992 }
6993 return new ArrayList<>(emergencyNumbers);
6994 } finally {
6995 Binder.restoreCallingIdentity(identity);
6996 }
6997 }
6998
chen xud6b45bd2018-10-30 22:27:10 -07006999 @Override
7000 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7001 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7002 Phone phone = getPhone(subId);
7003 if (phone == null) {
7004 return null;
7005 }
7006 final long identity = Binder.clearCallingIdentity();
7007 try {
7008 UiccProfile profile = UiccController.getInstance()
7009 .getUiccProfileForPhone(phone.getPhoneId());
7010 if (profile != null) {
7011 return profile.getCertsFromCarrierPrivilegeAccessRules();
7012 }
7013 } finally {
7014 Binder.restoreCallingIdentity(identity);
7015 }
7016 return null;
7017 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007018
7019 /**
7020 * Enable or disable a modem stack.
7021 */
7022 @Override
7023 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7024 enforceModifyPermission();
7025
7026 final long identity = Binder.clearCallingIdentity();
7027 try {
7028 Phone phone = PhoneFactory.getPhone(slotIndex);
7029 if (phone == null) {
7030 return false;
7031 } else {
7032 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7033 }
7034 } finally {
7035 Binder.restoreCallingIdentity(identity);
7036 }
7037 }
Michelecea4cf22018-12-21 15:00:11 -08007038
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007039 /**
7040 * Whether a modem stack is enabled or not.
7041 */
7042 @Override
7043 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage) {
7044 Phone phone = PhoneFactory.getPhone(slotIndex);
7045 if (phone == null) return false;
7046
7047 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7048 mApp, phone.getSubId(), callingPackage, "isModemEnabledForSlot")) {
7049 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7050 }
7051
7052 final long identity = Binder.clearCallingIdentity();
7053 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007054 try {
7055 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7056 } catch (NoSuchElementException ex) {
7057 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7058 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007059 } finally {
7060 Binder.restoreCallingIdentity(identity);
7061 }
7062 }
7063
Michelecea4cf22018-12-21 15:00:11 -08007064 @Override
Michele0ea7d782019-03-19 14:58:42 -07007065 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007066 enforceModifyPermission();
7067
7068 final long identity = Binder.clearCallingIdentity();
7069 try {
7070 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007071 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007072 .commit();
7073 } finally {
7074 Binder.restoreCallingIdentity(identity);
7075 }
7076 }
7077
7078 @Override
Michele0ea7d782019-03-19 14:58:42 -07007079 @TelephonyManager.IsMultiSimSupportedResult
7080 public int isMultiSimSupported(String callingPackage) {
Michele4245e952019-02-04 11:36:23 -08007081 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Michele0ea7d782019-03-19 14:58:42 -07007082 getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) {
7083 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007084 }
Michelecea4cf22018-12-21 15:00:11 -08007085
7086 final long identity = Binder.clearCallingIdentity();
7087 try {
Michele0ea7d782019-03-19 14:58:42 -07007088 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007089 } finally {
7090 Binder.restoreCallingIdentity(identity);
7091 }
7092 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007093
Michele0ea7d782019-03-19 14:58:42 -07007094 @TelephonyManager.IsMultiSimSupportedResult
7095 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007096 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7097 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7098 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007099 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7100 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007101 }
7102 // Check if the hardware supports multisim functionality. If usage of multisim is not
7103 // supported by the modem, indicate that it is restricted.
7104 PhoneCapability staticCapability =
7105 mPhoneConfigurationManager.getStaticPhoneCapability();
7106 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007107 loge("isMultiSimSupportedInternal: no static configuration available");
7108 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007109 }
7110 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007111 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7112 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007113 }
7114 // Check if support of multiple SIMs is restricted by carrier
7115 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07007116 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007117 }
7118
Michele0ea7d782019-03-19 14:58:42 -07007119 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007120 }
7121
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007122 /**
7123 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007124 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7125 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7126 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007127 * @param numOfSims number of active sims we want to switch to
7128 */
7129 @Override
7130 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007131 if (numOfSims == 1) {
7132 enforceModifyPermission();
7133 } else {
7134 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7135 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
7136 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007137 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08007138
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007139 try {
Michele30b57b22019-03-01 12:01:14 -08007140 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07007141 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08007142 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
7143 return;
7144 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007145 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7146 } finally {
7147 Binder.restoreCallingIdentity(identity);
7148 }
7149 }
7150
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09007151 @Override
7152 public boolean isApplicationOnUicc(int subId, int appType) {
7153 enforceReadPrivilegedPermission("isApplicationOnUicc");
7154 Phone phone = getPhone(subId);
7155 if (phone == null) {
7156 return false;
7157 }
7158 final long identity = Binder.clearCallingIdentity();
7159 try {
7160 UiccCard uiccCard = phone.getUiccCard();
7161 if (uiccCard == null) {
7162 return false;
7163 }
7164 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7165 if (uiccProfile == null) {
7166 return false;
7167 }
7168 if (TelephonyManager.APPTYPE_SIM <= appType
7169 && appType <= TelephonyManager.APPTYPE_ISIM) {
7170 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
7171 }
7172 return false;
7173 } finally {
7174 Binder.restoreCallingIdentity(identity);
7175 }
7176 }
7177
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007178 /**
chen xub4baa772019-04-03 10:23:41 -07007179 * Get whether making changes to modem configurations will trigger reboot.
7180 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007181 */
7182 @Override
chen xub4baa772019-04-03 10:23:41 -07007183 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage) {
7184 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7185 mApp, subId, callingPackage, "doesSwitchMultiSimConfigTriggerReboot")) {
7186 return false;
7187 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007188 final long identity = Binder.clearCallingIdentity();
7189 try {
7190 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
7191 } finally {
7192 Binder.restoreCallingIdentity(identity);
7193 }
7194 }
7195
Nathan Harold29f5f052019-02-15 13:41:57 -08007196 private void updateModemStateMetrics() {
7197 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
7198 // TODO: check the state for each modem if the api is ready.
7199 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
7200 }
7201
Pengquan Meng3889a572019-01-23 11:16:29 -08007202 @Override
7203 public int[] getSlotsMapping() {
7204 enforceReadPrivilegedPermission("getSlotsMapping");
7205
7206 final long identity = Binder.clearCallingIdentity();
7207 try {
7208 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
7209 // All logical slots should have a mapping to a physical slot.
7210 int[] logicalSlotsMapping = new int[phoneCount];
7211 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
7212 for (int i = 0; i < slotInfos.length; i++) {
7213 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
7214 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
7215 }
7216 }
7217 return logicalSlotsMapping;
7218 } finally {
7219 Binder.restoreCallingIdentity(identity);
7220 }
7221 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007222
7223 /**
7224 * Get the IRadio HAL Version
7225 */
7226 @Override
7227 public int getRadioHalVersion() {
7228 Phone phone = getDefaultPhone();
7229 if (phone == null) return -1;
7230 HalVersion hv = phone.getHalVersion();
7231 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7232 return hv.major * 100 + hv.minor;
7233 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007234
7235 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007236 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7237 * corresponding network requests on a subId.
7238 *
7239 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007240 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007241 * 2) APN is un-metered for this subscription, or
7242 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
7243 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on.
7244 *
7245 * @return whether data is allowed for a apn type.
7246 *
7247 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007248 */
7249 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007250 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007251 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Malcolm Chene5ad5792019-04-18 13:51:02 -07007252 mApp, subId, callingPackage, "isDataEnabledForApn")) {
7253 throw new SecurityException("Needs READ_PHONE_STATE for isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007254 }
7255
7256 // Now that all security checks passes, perform the operation as ourselves.
7257 final long identity = Binder.clearCallingIdentity();
7258 try {
7259 Phone phone = getPhone(subId);
7260 if (phone == null) return false;
7261
Jack Yu41407ee2019-05-13 16:54:09 -07007262 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07007263 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7264 } finally {
7265 Binder.restoreCallingIdentity(identity);
7266 }
7267 }
7268
7269 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07007270 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07007271 enforceReadPrivilegedPermission("isApnMetered");
7272
7273 // Now that all security checks passes, perform the operation as ourselves.
7274 final long identity = Binder.clearCallingIdentity();
7275 try {
7276 Phone phone = getPhone(subId);
7277 if (phone == null) return true; // By default return true.
7278
Jack Yu41407ee2019-05-13 16:54:09 -07007279 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007280 } finally {
7281 Binder.restoreCallingIdentity(identity);
7282 }
7283 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007284
7285 @Override
7286 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
7287 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
7288 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
7289 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
7290 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
7291 }
7292 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
7293 Intent intent = new Intent();
7294 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
7295 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7296 // Bring up choose default SMS subscription dialog right now
7297 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
7298 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
7299 mApp.startActivity(intent);
7300 }
chen xud5ca2d52019-05-28 15:20:57 -07007301
7302 @Override
7303 public String getMmsUAProfUrl(int subId) {
7304 //TODO investigate if this API should require proper permission check in R b/133791609
7305 final long identity = Binder.clearCallingIdentity();
7306 try {
7307 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7308 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
7309 } finally {
7310 Binder.restoreCallingIdentity(identity);
7311 }
7312 }
7313
7314 @Override
7315 public String getMmsUserAgent(int subId) {
7316 //TODO investigate if this API should require proper permission check in R b/133791609
7317 final long identity = Binder.clearCallingIdentity();
7318 try {
7319 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7320 .getString(com.android.internal.R.string.config_mms_user_agent);
7321 } finally {
7322 Binder.restoreCallingIdentity(identity);
7323 }
7324 }
Jack Yub07d4972019-05-28 16:12:25 -07007325
7326 @Override
7327 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
7328 enforceModifyPermission();
7329
7330 // Now that all security checks passes, perform the operation as ourselves.
7331 final long identity = Binder.clearCallingIdentity();
7332 try {
7333 Phone phone = getPhone(subId);
7334 if (phone == null) return false;
7335
7336 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
7337 } finally {
7338 Binder.restoreCallingIdentity(identity);
7339 }
7340 }
7341
7342 @Override
7343 public boolean isDataAllowedInVoiceCall(int subId) {
7344 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
7345
7346 // Now that all security checks passes, perform the operation as ourselves.
7347 final long identity = Binder.clearCallingIdentity();
7348 try {
7349 Phone phone = getPhone(subId);
7350 if (phone == null) return false;
7351
7352 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
7353 } finally {
7354 Binder.restoreCallingIdentity(identity);
7355 }
7356 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07007357
7358 /**
7359 * Updates whether conference event pacakge handling is enabled.
7360 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
7361 * otherwise.
7362 */
7363 @Override
7364 public void setCepEnabled(boolean isCepEnabled) {
7365 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
7366
7367 final long identity = Binder.clearCallingIdentity();
7368 try {
7369 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
7370 for (Phone phone : PhoneFactory.getPhones()) {
7371 Phone defaultPhone = phone.getImsPhone();
7372 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7373 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7374 ImsPhoneCallTracker imsPhoneCallTracker =
7375 (ImsPhoneCallTracker) imsPhone.getCallTracker();
7376 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
7377 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
7378 + imsPhone.getMsisdn());
7379 }
7380 }
7381 } finally {
7382 Binder.restoreCallingIdentity(identity);
7383 }
7384 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007385}