blob: 9ab4549de78fb3c798a7b94df4b6b3b5451fb768 [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;
Hall Liua1548bd2019-12-24 14:14:12 -080025import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070026import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070027import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080028import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070029import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070030import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070031import android.content.Context;
32import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070033import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070034import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070035import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080036import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070037import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070038import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070039import android.net.Uri;
40import android.os.AsyncResult;
41import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080042import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070043import android.os.Bundle;
44import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070045import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070046import android.os.Looper;
47import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070048import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080049import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070050import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070051import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080052import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070053import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070054import android.os.ServiceManager;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070055import android.os.ServiceSpecificException;
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;
Naina Nallurid63128d2019-09-17 14:10:30 -070060import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080061import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070062import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090063import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080064import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080065import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070066import android.telecom.TelecomManager;
Chen Xu227e06f2019-09-26 22:48:11 -070067import android.telephony.Annotation.ApnType;
Junda Liu12f7d802015-05-01 12:06:44 -070068import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080069import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070070import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080071import android.telephony.CellIdentityCdma;
72import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070073import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070074import android.telephony.CellInfoGsm;
75import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070076import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070077import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070078import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080079import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070080import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080081import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070082import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080083import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080084import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070085import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080086import android.telephony.RadioAccessSpecifier;
Tyler Gunn65d45c22017-06-05 11:22:26 -070087import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070088import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080089import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080090import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080091import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070092import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070093import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080094import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080095import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000096import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070097import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070098import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -080099import android.telephony.data.ApnSetting;
100import android.telephony.emergency.EmergencyNumber;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700101import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800102import android.telephony.ims.ProvisioningManager;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700103import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700104import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800105import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700106import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800107import android.telephony.ims.aidl.IImsMmTelFeature;
108import android.telephony.ims.aidl.IImsRcsFeature;
109import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700110import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700111import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800112import android.telephony.ims.feature.MmTelFeature;
113import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800114import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700115import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800116import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700117import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800118import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800119import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800120
Andrew Lee312e8172014-10-23 17:01:36 -0700121import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800122import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700123import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700124import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700125import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800126import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700127import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700128import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700129import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800130import com.android.internal.telephony.HalVersion;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700131import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800132import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700133import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800134import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700135import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700136import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700137import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700138import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700139import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800140import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700141import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700142import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700143import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700144import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700145import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700146import com.android.internal.telephony.ServiceStateTracker;
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;
Meng Wangafbc5852019-09-19 17:37:13 -0700158import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700159import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800160import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700161import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800162import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700163import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800164import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700165import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800166import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000167import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800168import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700169import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800170import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700171import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700172import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800173import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700174import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700175import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800176
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700177import java.io.FileDescriptor;
178import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700179import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800180import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800181import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800182import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800183import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100184import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800185import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700186import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800187import java.util.Set;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700188
189/**
190 * Implementation of the ITelephony interface.
191 */
Santos Cordon117fee72014-05-16 17:56:12 -0700192public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700193 private static final String LOG_TAG = "PhoneInterfaceManager";
194 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
195 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800196 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700197
198 // Message codes used with mMainThreadHandler
199 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700200 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
201 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700202 private static final int CMD_OPEN_CHANNEL = 9;
203 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
204 private static final int CMD_CLOSE_CHANNEL = 11;
205 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800206 private static final int CMD_NV_READ_ITEM = 13;
207 private static final int EVENT_NV_READ_ITEM_DONE = 14;
208 private static final int CMD_NV_WRITE_ITEM = 15;
209 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
210 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
211 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700212 private static final int CMD_RESET_MODEM_CONFIG = 19;
213 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800214 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
215 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
216 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
217 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800218 private static final int CMD_SEND_ENVELOPE = 25;
219 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000220 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
221 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700222 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
223 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
224 private static final int CMD_EXCHANGE_SIM_IO = 31;
225 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800226 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
227 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700228 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
229 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700230 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
231 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700232 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
233 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
234 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
235 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700236 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
237 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
238 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
239 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700240 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800241 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
242 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000243 private static final int CMD_SWITCH_SLOTS = 50;
244 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700245 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
246 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
247 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
248 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
249 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
250 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
251 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
252 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700253 private static final int CMD_GET_ALL_CELL_INFO = 60;
254 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
255 private static final int CMD_GET_CELL_LOCATION = 62;
256 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700257 private static final int CMD_MODEM_REBOOT = 64;
258 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700259 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
260 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800261 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
262 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700263 private static final int CMD_GET_MODEM_STATUS = 70;
264 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700265 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
266 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700267 private static final int CMD_ERASE_MODEM_CONFIG = 74;
268 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700269
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800270 // Parameters of select command.
271 private static final int SELECT_COMMAND = 0xA4;
272 private static final int SELECT_P1 = 0x04;
273 private static final int SELECT_P2 = 0;
274 private static final int SELECT_P3 = 0x10;
275
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700276 /** The singleton instance. */
277 private static PhoneInterfaceManager sInstance;
278
Wink Saville3ab207e2014-11-20 13:07:20 -0800279 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800280 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800281 private ImsResolver mImsResolver;
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 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700306 * Experiment flag to enable erase modem config on reset network, default value is false
307 */
308 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
309 "reset_network_erase_modem_config_enabled";
310
311 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700312 * A request object to use for transmitting data to an ICC.
313 */
314 private static final class IccAPDUArgument {
315 public int channel, cla, command, p1, p2, p3;
316 public String data;
317
318 public IccAPDUArgument(int channel, int cla, int command,
319 int p1, int p2, int p3, String data) {
320 this.channel = channel;
321 this.cla = cla;
322 this.command = command;
323 this.p1 = p1;
324 this.p2 = p2;
325 this.p3 = p3;
326 this.data = data;
327 }
328 }
329
330 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700331 * A request object to use for transmitting data to an ICC.
332 */
333 private static final class ManualNetworkSelectionArgument {
334 public OperatorInfo operatorInfo;
335 public boolean persistSelection;
336
337 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
338 this.operatorInfo = operatorInfo;
339 this.persistSelection = persistSelection;
340 }
341 }
342
343 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700344 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
345 * request after sending. The main thread will notify the request when it is complete.
346 */
347 private static final class MainThreadRequest {
348 /** The argument to use for the request */
349 public Object argument;
350 /** The result of the request that is run on the main thread */
351 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800352 // The subscriber id that this request applies to. Defaults to
353 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
354 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700355
Nathan Harold92bed182018-10-12 18:16:49 -0700356 // In cases where subId is unavailable, the caller needs to specify the phone.
357 public Phone phone;
358
vagdeviaf9a5b92018-08-15 16:01:53 -0700359 public WorkSource workSource;
360
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700361 public MainThreadRequest(Object argument) {
362 this.argument = argument;
363 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800364
Nathan Harold92bed182018-10-12 18:16:49 -0700365 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
366 this.argument = argument;
367 if (phone != null) {
368 this.phone = phone;
369 }
370 this.workSource = workSource;
371 }
372
vagdeviaf9a5b92018-08-15 16:01:53 -0700373 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800374 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800375 if (subId != null) {
376 this.subId = subId;
377 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700378 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800379 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700380 }
381
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800382 private static final class IncomingThirdPartyCallArgs {
383 public final ComponentName component;
384 public final String callId;
385 public final String callerDisplayName;
386
387 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
388 String callerDisplayName) {
389 this.component = component;
390 this.callId = callId;
391 this.callerDisplayName = callerDisplayName;
392 }
393 }
394
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700395 /**
396 * A handler that processes messages on the main thread in the phone process. Since many
397 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
398 * inbound binder threads to the main thread in the phone process. The Binder thread
399 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
400 * on, which will be notified when the operation completes and will contain the result of the
401 * request.
402 *
403 * <p>If a MainThreadRequest object is provided in the msg.obj field,
404 * note that request.result must be set to something non-null for the calling thread to
405 * unblock.
406 */
407 private final class MainThreadHandler extends Handler {
408 @Override
409 public void handleMessage(Message msg) {
410 MainThreadRequest request;
411 Message onCompleted;
412 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800413 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700414 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800415 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700416
417 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700418 case CMD_HANDLE_USSD_REQUEST: {
419 request = (MainThreadRequest) msg.obj;
420 final Phone phone = getPhoneFromRequest(request);
421 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
422 String ussdRequest = ussdObject.first;
423 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700424
Pengquan Menga1bb6272018-09-06 09:59:22 -0700425 if (!isUssdApiAllowed(request.subId)) {
426 // Carrier does not support use of this API, return failure.
427 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
428 UssdResponse response = new UssdResponse(ussdRequest, null);
429 Bundle returnData = new Bundle();
430 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
431 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700432
Pengquan Menga1bb6272018-09-06 09:59:22 -0700433 request.result = true;
434 notifyRequester(request);
435 return;
436 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700437
Pengquan Menga1bb6272018-09-06 09:59:22 -0700438 try {
439 request.result = phone != null
440 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
441 } catch (CallStateException cse) {
442 request.result = false;
443 }
444 // Wake up the requesting thread
445 notifyRequester(request);
446 break;
pkanwar32d516d2016-10-14 19:37:38 -0700447 }
448
Yorke Lee716f67e2015-06-17 15:39:16 -0700449 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700450 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700451 final Phone phone = getPhoneFromRequest(request);
452 request.result = phone != null ?
453 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
454 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700455 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700456 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700457 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700458 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700459
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700460 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700461 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700462 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800463 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700464 if (uiccCard == null) {
465 loge("iccTransmitApduLogicalChannel: No UICC");
466 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700467 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700468 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700469 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
470 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700471 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700472 iccArgument.channel, iccArgument.cla, iccArgument.command,
473 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700474 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700475 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700476 break;
477
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700478 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700479 ar = (AsyncResult) msg.obj;
480 request = (MainThreadRequest) ar.userObj;
481 if (ar.exception == null && ar.result != null) {
482 request.result = ar.result;
483 } else {
484 request.result = new IccIoResult(0x6F, 0, (byte[])null);
485 if (ar.result == null) {
486 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800487 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700488 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800489 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700490 } else {
491 loge("iccTransmitApduLogicalChannel: Unknown exception");
492 }
493 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700494 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700495 break;
496
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700497 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
498 request = (MainThreadRequest) msg.obj;
499 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800500 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700501 if (uiccCard == null) {
502 loge("iccTransmitApduBasicChannel: No UICC");
503 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700504 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700505 } else {
506 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
507 request);
508 uiccCard.iccTransmitApduBasicChannel(
509 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
510 iccArgument.p3, iccArgument.data, onCompleted);
511 }
512 break;
513
514 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
515 ar = (AsyncResult) msg.obj;
516 request = (MainThreadRequest) ar.userObj;
517 if (ar.exception == null && ar.result != null) {
518 request.result = ar.result;
519 } else {
520 request.result = new IccIoResult(0x6F, 0, (byte[])null);
521 if (ar.result == null) {
522 loge("iccTransmitApduBasicChannel: Empty response");
523 } else if (ar.exception instanceof CommandException) {
524 loge("iccTransmitApduBasicChannel: CommandException: " +
525 ar.exception);
526 } else {
527 loge("iccTransmitApduBasicChannel: Unknown exception");
528 }
529 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700530 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700531 break;
532
533 case CMD_EXCHANGE_SIM_IO:
534 request = (MainThreadRequest) msg.obj;
535 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800536 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700537 if (uiccCard == null) {
538 loge("iccExchangeSimIO: No UICC");
539 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700540 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700541 } else {
542 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
543 request);
544 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
545 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
546 iccArgument.data, onCompleted);
547 }
548 break;
549
550 case EVENT_EXCHANGE_SIM_IO_DONE:
551 ar = (AsyncResult) msg.obj;
552 request = (MainThreadRequest) ar.userObj;
553 if (ar.exception == null && ar.result != null) {
554 request.result = ar.result;
555 } else {
556 request.result = new IccIoResult(0x6f, 0, (byte[])null);
557 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700558 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700559 break;
560
Derek Tan4d5e5c12014-02-04 11:54:58 -0800561 case CMD_SEND_ENVELOPE:
562 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800563 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700564 if (uiccCard == null) {
565 loge("sendEnvelopeWithStatus: No UICC");
566 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700567 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700568 } else {
569 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
570 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
571 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800572 break;
573
574 case EVENT_SEND_ENVELOPE_DONE:
575 ar = (AsyncResult) msg.obj;
576 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700577 if (ar.exception == null && ar.result != null) {
578 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800579 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700580 request.result = new IccIoResult(0x6F, 0, (byte[])null);
581 if (ar.result == null) {
582 loge("sendEnvelopeWithStatus: Empty response");
583 } else if (ar.exception instanceof CommandException) {
584 loge("sendEnvelopeWithStatus: CommandException: " +
585 ar.exception);
586 } else {
587 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
588 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800589 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700590 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800591 break;
592
Shishir Agrawal566b7612013-10-28 14:41:00 -0700593 case CMD_OPEN_CHANNEL:
594 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800595 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800596 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700597 if (uiccCard == null) {
598 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800599 request.result = new IccOpenLogicalChannelResponse(-1,
600 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700601 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700602 } else {
603 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800604 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
605 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700606 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700607 break;
608
609 case EVENT_OPEN_CHANNEL_DONE:
610 ar = (AsyncResult) msg.obj;
611 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700612 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700613 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700614 int[] result = (int[]) ar.result;
615 int channelId = result[0];
616 byte[] selectResponse = null;
617 if (result.length > 1) {
618 selectResponse = new byte[result.length - 1];
619 for (int i = 1; i < result.length; ++i) {
620 selectResponse[i - 1] = (byte) result[i];
621 }
622 }
623 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700624 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700625 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700626 if (ar.result == null) {
627 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700628 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700629 if (ar.exception != null) {
630 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
631 }
632
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700633 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700634 if (ar.exception instanceof CommandException) {
635 CommandException.Error error =
636 ((CommandException) (ar.exception)).getCommandError();
637 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700638 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700639 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700640 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700641 }
642 }
643 openChannelResp = new IccOpenLogicalChannelResponse(
644 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700645 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700646 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700647 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700648 break;
649
650 case CMD_CLOSE_CHANNEL:
651 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800652 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700653 if (uiccCard == null) {
654 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900655 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700656 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700657 } else {
658 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
659 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
660 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700661 break;
662
663 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800664 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
665 break;
666
667 case CMD_NV_READ_ITEM:
668 request = (MainThreadRequest) msg.obj;
669 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800670 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
671 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800672 break;
673
674 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700675 ar = (AsyncResult) msg.obj;
676 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800677 if (ar.exception == null && ar.result != null) {
678 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700679 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800680 request.result = "";
681 if (ar.result == null) {
682 loge("nvReadItem: Empty response");
683 } else if (ar.exception instanceof CommandException) {
684 loge("nvReadItem: CommandException: " +
685 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700686 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800687 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700688 }
689 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700690 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700691 break;
692
Jake Hambye994d462014-02-03 13:10:13 -0800693 case CMD_NV_WRITE_ITEM:
694 request = (MainThreadRequest) msg.obj;
695 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
696 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800697 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700698 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800699 break;
700
701 case EVENT_NV_WRITE_ITEM_DONE:
702 handleNullReturnEvent(msg, "nvWriteItem");
703 break;
704
705 case CMD_NV_WRITE_CDMA_PRL:
706 request = (MainThreadRequest) msg.obj;
707 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800708 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800709 break;
710
711 case EVENT_NV_WRITE_CDMA_PRL_DONE:
712 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
713 break;
714
chen xu6dac5ab2018-10-26 17:39:23 -0700715 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800716 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700717 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800718 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800719 break;
720
chen xu6dac5ab2018-10-26 17:39:23 -0700721 case EVENT_RESET_MODEM_CONFIG_DONE:
722 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800723 break;
724
Jake Hamby7c27be32014-03-03 13:25:59 -0800725 case CMD_GET_PREFERRED_NETWORK_TYPE:
726 request = (MainThreadRequest) msg.obj;
727 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700728 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800729 break;
730
731 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
732 ar = (AsyncResult) msg.obj;
733 request = (MainThreadRequest) ar.userObj;
734 if (ar.exception == null && ar.result != null) {
735 request.result = ar.result; // Integer
736 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800737 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800738 if (ar.result == null) {
739 loge("getPreferredNetworkType: Empty response");
740 } else if (ar.exception instanceof CommandException) {
741 loge("getPreferredNetworkType: CommandException: " +
742 ar.exception);
743 } else {
744 loge("getPreferredNetworkType: Unknown exception");
745 }
746 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700747 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800748 break;
749
750 case CMD_SET_PREFERRED_NETWORK_TYPE:
751 request = (MainThreadRequest) msg.obj;
752 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
753 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700754 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800755 break;
756
757 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
758 handleNullReturnEvent(msg, "setPreferredNetworkType");
759 break;
760
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000761 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
762 request = (MainThreadRequest)msg.obj;
763 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800764 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000765 break;
766
767 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
768 ar = (AsyncResult)msg.obj;
769 request = (MainThreadRequest)ar.userObj;
770 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700771 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000772 break;
773
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800774 case CMD_SET_VOICEMAIL_NUMBER:
775 request = (MainThreadRequest) msg.obj;
776 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
777 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800778 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
779 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800780 break;
781
782 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
783 handleNullReturnEvent(msg, "setVoicemailNumber");
784 break;
785
Stuart Scott54788802015-03-30 13:18:01 -0700786 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
787 request = (MainThreadRequest) msg.obj;
788 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
789 request);
790 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
791 break;
792
793 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
794 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
795 break;
796
Shishir Agrawal302c8692015-06-19 13:49:39 -0700797 case CMD_PERFORM_NETWORK_SCAN:
798 request = (MainThreadRequest) msg.obj;
799 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
800 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
801 break;
802
803 case EVENT_PERFORM_NETWORK_SCAN_DONE:
804 ar = (AsyncResult) msg.obj;
805 request = (MainThreadRequest) ar.userObj;
806 CellNetworkScanResult cellScanResult;
807 if (ar.exception == null && ar.result != null) {
808 cellScanResult = new CellNetworkScanResult(
809 CellNetworkScanResult.STATUS_SUCCESS,
810 (List<OperatorInfo>) ar.result);
811 } else {
812 if (ar.result == null) {
813 loge("getCellNetworkScanResults: Empty response");
814 }
815 if (ar.exception != null) {
816 loge("getCellNetworkScanResults: Exception: " + ar.exception);
817 }
818 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
819 if (ar.exception instanceof CommandException) {
820 CommandException.Error error =
821 ((CommandException) (ar.exception)).getCommandError();
822 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
823 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
824 } else if (error == CommandException.Error.GENERIC_FAILURE) {
825 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
826 }
827 }
828 cellScanResult = new CellNetworkScanResult(errorCode, null);
829 }
830 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700831 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700832 break;
833
834 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
835 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700836 ManualNetworkSelectionArgument selArg =
837 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700838 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
839 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700840 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
841 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700842 break;
843
844 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700845 ar = (AsyncResult) msg.obj;
846 request = (MainThreadRequest) ar.userObj;
847 if (ar.exception == null) {
848 request.result = true;
849 } else {
850 request.result = false;
851 loge("setNetworkSelectionModeManual " + ar.exception);
852 }
853 notifyRequester(request);
854 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700855 break;
856
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700857 case CMD_GET_MODEM_ACTIVITY_INFO:
858 request = (MainThreadRequest) msg.obj;
859 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -0700860 if (defaultPhone != null) {
861 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
862 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700863 break;
864
865 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
866 ar = (AsyncResult) msg.obj;
867 request = (MainThreadRequest) ar.userObj;
868 if (ar.exception == null && ar.result != null) {
869 request.result = ar.result;
870 } else {
871 if (ar.result == null) {
872 loge("queryModemActivityInfo: Empty response");
873 } else if (ar.exception instanceof CommandException) {
874 loge("queryModemActivityInfo: CommandException: " +
875 ar.exception);
876 } else {
877 loge("queryModemActivityInfo: Unknown exception");
878 }
879 }
Amit Mahajand4766222016-01-28 15:28:28 -0800880 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
881 if (request.result == null) {
Peter Collingbournec00e9022019-11-26 09:56:26 -0800882 request.result = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Amit Mahajand4766222016-01-28 15:28:28 -0800883 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700884 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700885 break;
886
Meng Wang1a7c35a2016-05-05 20:56:15 -0700887 case CMD_SET_ALLOWED_CARRIERS:
888 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -0800889 CarrierRestrictionRules argument =
890 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700891 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -0800892 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700893 break;
894
895 case EVENT_SET_ALLOWED_CARRIERS_DONE:
896 ar = (AsyncResult) msg.obj;
897 request = (MainThreadRequest) ar.userObj;
898 if (ar.exception == null && ar.result != null) {
899 request.result = ar.result;
900 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800901 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
902 if (ar.exception instanceof CommandException) {
903 loge("setAllowedCarriers: CommandException: " + ar.exception);
904 CommandException.Error error =
905 ((CommandException) (ar.exception)).getCommandError();
906 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
907 request.result =
908 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
909 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700910 } else {
911 loge("setAllowedCarriers: Unknown exception");
912 }
913 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700914 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700915 break;
916
917 case CMD_GET_ALLOWED_CARRIERS:
918 request = (MainThreadRequest) msg.obj;
919 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800920 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700921 break;
922
923 case EVENT_GET_ALLOWED_CARRIERS_DONE:
924 ar = (AsyncResult) msg.obj;
925 request = (MainThreadRequest) ar.userObj;
926 if (ar.exception == null && ar.result != null) {
927 request.result = ar.result;
928 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800929 request.result = new IllegalStateException(
930 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700931 if (ar.result == null) {
932 loge("getAllowedCarriers: Empty response");
933 } else if (ar.exception instanceof CommandException) {
934 loge("getAllowedCarriers: CommandException: " +
935 ar.exception);
936 } else {
937 loge("getAllowedCarriers: Unknown exception");
938 }
939 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700940 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700941 break;
942
Nathan Haroldb3014052017-01-25 15:57:32 -0800943 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
944 ar = (AsyncResult) msg.obj;
945 request = (MainThreadRequest) ar.userObj;
946 if (ar.exception == null && ar.result != null) {
947 request.result = ar.result;
948 } else {
949 request.result = new IllegalArgumentException(
950 "Failed to retrieve Forbidden Plmns");
951 if (ar.result == null) {
952 loge("getForbiddenPlmns: Empty response");
953 } else {
954 loge("getForbiddenPlmns: Unknown exception");
955 }
956 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700957 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800958 break;
959
960 case CMD_GET_FORBIDDEN_PLMNS:
961 request = (MainThreadRequest) msg.obj;
962 uiccCard = getUiccCardFromRequest(request);
963 if (uiccCard == null) {
964 loge("getForbiddenPlmns() UiccCard is null");
965 request.result = new IllegalArgumentException(
966 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700967 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800968 break;
969 }
970 Integer appType = (Integer) request.argument;
971 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
972 if (uiccApp == null) {
973 loge("getForbiddenPlmns() no app with specified type -- "
974 + appType);
975 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700976 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800977 break;
978 } else {
979 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
980 + " specified type -- " + appType);
981 }
982 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
983 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
984 onCompleted);
985 break;
986
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000987 case CMD_SWITCH_SLOTS:
988 request = (MainThreadRequest) msg.obj;
989 int[] physicalSlots = (int[]) request.argument;
990 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
991 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
992 break;
993
994 case EVENT_SWITCH_SLOTS_DONE:
995 ar = (AsyncResult) msg.obj;
996 request = (MainThreadRequest) ar.userObj;
997 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700998 notifyRequester(request);
999 break;
1000 case CMD_GET_NETWORK_SELECTION_MODE:
1001 request = (MainThreadRequest) msg.obj;
1002 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1003 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1004 break;
1005
1006 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1007 ar = (AsyncResult) msg.obj;
1008 request = (MainThreadRequest) ar.userObj;
1009 if (ar.exception != null) {
1010 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1011 } else {
1012 int mode = ((int[]) ar.result)[0];
1013 if (mode == 0) {
1014 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1015 } else {
1016 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1017 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001018 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001019 notifyRequester(request);
1020 break;
1021 case CMD_GET_CDMA_ROAMING_MODE:
1022 request = (MainThreadRequest) msg.obj;
1023 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1024 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1025 break;
1026 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1027 ar = (AsyncResult) msg.obj;
1028 request = (MainThreadRequest) ar.userObj;
1029 if (ar.exception != null) {
1030 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1031 } else {
1032 request.result = ((int[]) ar.result)[0];
1033 }
1034 notifyRequester(request);
1035 break;
1036 case CMD_SET_CDMA_ROAMING_MODE:
1037 request = (MainThreadRequest) msg.obj;
1038 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1039 int mode = (int) request.argument;
1040 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1041 break;
1042 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1043 ar = (AsyncResult) msg.obj;
1044 request = (MainThreadRequest) ar.userObj;
1045 request.result = ar.exception == null;
1046 notifyRequester(request);
1047 break;
1048 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1049 request = (MainThreadRequest) msg.obj;
1050 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1051 int subscriptionMode = (int) request.argument;
1052 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1053 break;
1054 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1055 ar = (AsyncResult) msg.obj;
1056 request = (MainThreadRequest) ar.userObj;
1057 request.result = ar.exception == null;
1058 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001059 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001060 case CMD_GET_ALL_CELL_INFO:
1061 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001062 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001063 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001064 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001065 case EVENT_GET_ALL_CELL_INFO_DONE:
1066 ar = (AsyncResult) msg.obj;
1067 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001068 // If a timeout occurs, the response will be null
1069 request.result = (ar.exception == null && ar.result != null)
1070 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001071 synchronized (request) {
1072 request.notifyAll();
1073 }
1074 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001075 case CMD_REQUEST_CELL_INFO_UPDATE:
1076 request = (MainThreadRequest) msg.obj;
1077 request.phone.requestCellInfoUpdate(request.workSource,
1078 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1079 break;
1080 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1081 ar = (AsyncResult) msg.obj;
1082 request = (MainThreadRequest) ar.userObj;
1083 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1084 try {
1085 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001086 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001087 cb.onError(
1088 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1089 ar.exception.getClass().getName(),
1090 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001091 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001092 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001093 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001094 } else {
1095 // use the result as returned
1096 cb.onCellInfo((List<CellInfo>) ar.result);
1097 }
1098 } catch (RemoteException re) {
1099 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1100 }
1101 break;
1102 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001103 request = (MainThreadRequest) msg.obj;
1104 WorkSource ws = (WorkSource) request.argument;
1105 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001106 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001107 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001108 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001109 ar = (AsyncResult) msg.obj;
1110 request = (MainThreadRequest) ar.userObj;
1111 if (ar.exception == null) {
1112 request.result = ar.result;
1113 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001114 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001115 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001116 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001117 }
1118
1119 synchronized (request) {
1120 request.notifyAll();
1121 }
1122 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001123 case CMD_MODEM_REBOOT:
1124 request = (MainThreadRequest) msg.obj;
1125 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001126 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001127 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001128 case EVENT_CMD_MODEM_REBOOT_DONE:
1129 handleNullReturnEvent(msg, "rebootModem");
1130 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001131 case CMD_REQUEST_ENABLE_MODEM:
1132 request = (MainThreadRequest) msg.obj;
1133 boolean enable = (boolean) request.argument;
1134 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001135 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001136 PhoneConfigurationManager.getInstance()
1137 .enablePhone(request.phone, enable, onCompleted);
1138 break;
1139 case EVENT_ENABLE_MODEM_DONE:
1140 ar = (AsyncResult) msg.obj;
1141 request = (MainThreadRequest) ar.userObj;
1142 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001143 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001144 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001145 if ((boolean) request.result) {
1146 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1147 updateModemStateMetrics();
1148 } else {
1149 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1150 + ar.exception);
1151 }
1152 notifyRequester(request);
1153 break;
1154 case CMD_GET_MODEM_STATUS:
1155 request = (MainThreadRequest) msg.obj;
1156 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1157 PhoneConfigurationManager.getInstance()
1158 .getPhoneStatusFromModem(request.phone, onCompleted);
1159 break;
1160 case EVENT_GET_MODEM_STATUS_DONE:
1161 ar = (AsyncResult) msg.obj;
1162 request = (MainThreadRequest) ar.userObj;
1163 int id = request.phone.getPhoneId();
1164 if (ar.exception == null && ar.result != null) {
1165 request.result = ar.result;
1166 //update the cache as modem status has changed
1167 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1168 (boolean) request.result);
1169 } else {
1170 // Return true if modem status cannot be retrieved. For most cases,
1171 // modem status is on. And for older version modems, GET_MODEM_STATUS
1172 // and disable modem are not supported. Modem is always on.
1173 // TODO: this should be fixed in R to support a third
1174 // status UNKNOWN b/131631629
1175 request.result = true;
1176 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1177 + ar.exception);
1178 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001179 notifyRequester(request);
1180 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001181 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1182 ar = (AsyncResult) msg.obj;
1183 request = (MainThreadRequest) ar.userObj;
1184 if (ar.exception == null && ar.result != null) {
1185 request.result = ar.result;
1186 } else {
1187 request.result = -1;
1188 loge("Failed to set Forbidden Plmns");
1189 if (ar.result == null) {
1190 loge("setForbidenPlmns: Empty response");
1191 } else if (ar.exception != null) {
1192 loge("setForbiddenPlmns: Exception: " + ar.exception);
1193 request.result = -1;
1194 } else {
1195 loge("setForbiddenPlmns: Unknown exception");
1196 }
1197 }
1198 notifyRequester(request);
1199 break;
1200 case CMD_SET_FORBIDDEN_PLMNS:
1201 request = (MainThreadRequest) msg.obj;
1202 uiccCard = getUiccCardFromRequest(request);
1203 if (uiccCard == null) {
1204 loge("setForbiddenPlmns: UiccCard is null");
1205 request.result = -1;
1206 notifyRequester(request);
1207 break;
1208 }
1209 Pair<Integer, List<String>> setFplmnsArgs =
1210 (Pair<Integer, List<String>>) request.argument;
1211 appType = setFplmnsArgs.first;
1212 List<String> fplmns = setFplmnsArgs.second;
1213 uiccApp = uiccCard.getApplicationByType(appType);
1214 if (uiccApp == null) {
1215 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1216 request.result = -1;
1217 loge("Failed to get UICC App");
1218 notifyRequester(request);
1219 } else {
1220 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1221 ((SIMRecords) uiccApp.getIccRecords())
1222 .setForbiddenPlmns(onCompleted, fplmns);
1223 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001224 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001225 case CMD_ERASE_MODEM_CONFIG:
1226 request = (MainThreadRequest) msg.obj;
1227 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1228 defaultPhone.eraseModemConfig(onCompleted);
1229 break;
1230 case EVENT_ERASE_MODEM_CONFIG_DONE:
1231 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001232 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001233 default:
1234 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1235 break;
1236 }
1237 }
Jake Hambye994d462014-02-03 13:10:13 -08001238
Pengquan Menga1bb6272018-09-06 09:59:22 -07001239 private void notifyRequester(MainThreadRequest request) {
1240 synchronized (request) {
1241 request.notifyAll();
1242 }
1243 }
1244
Jake Hambye994d462014-02-03 13:10:13 -08001245 private void handleNullReturnEvent(Message msg, String command) {
1246 AsyncResult ar = (AsyncResult) msg.obj;
1247 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1248 if (ar.exception == null) {
1249 request.result = true;
1250 } else {
1251 request.result = false;
1252 if (ar.exception instanceof CommandException) {
1253 loge(command + ": CommandException: " + ar.exception);
1254 } else {
1255 loge(command + ": Unknown exception");
1256 }
1257 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001258 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001259 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001260 }
1261
1262 /**
1263 * Posts the specified command to be executed on the main thread,
1264 * waits for the request to complete, and returns the result.
1265 * @see #sendRequestAsync
1266 */
1267 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001268 return sendRequest(
1269 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001270 }
1271
1272 /**
1273 * Posts the specified command to be executed on the main thread,
1274 * waits for the request to complete, and returns the result.
1275 * @see #sendRequestAsync
1276 */
1277 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1278 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001279 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001280 }
1281
1282 /**
1283 * Posts the specified command to be executed on the main thread,
1284 * waits for the request to complete, and returns the result.
1285 * @see #sendRequestAsync
1286 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001287 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001288 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001289 }
1290
1291 /**
1292 * Posts the specified command to be executed on the main thread,
1293 * waits for the request to complete, and returns the result.
1294 * @see #sendRequestAsync
1295 */
Nathan Harold92bed182018-10-12 18:16:49 -07001296 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1297 return sendRequest(command, argument, subId, null, workSource);
1298 }
1299
1300 /**
1301 * Posts the specified command to be executed on the main thread,
1302 * waits for the request to complete, and returns the result.
1303 * @see #sendRequestAsync
1304 */
1305 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1306 return sendRequest(
1307 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1308 }
1309
1310 /**
1311 * Posts the specified command to be executed on the main thread,
1312 * waits for the request to complete, and returns the result.
1313 * @see #sendRequestAsync
1314 */
1315 private Object sendRequest(
1316 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001317 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1318 throw new RuntimeException("This method will deadlock if called from the main thread.");
1319 }
1320
Nathan Harold92bed182018-10-12 18:16:49 -07001321 MainThreadRequest request = null;
1322 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1323 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1324 } else if (phone != null) {
1325 request = new MainThreadRequest(argument, phone, workSource);
1326 } else {
1327 request = new MainThreadRequest(argument, subId, workSource);
1328 }
1329
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001330 Message msg = mMainThreadHandler.obtainMessage(command, request);
1331 msg.sendToTarget();
1332
1333 // Wait for the request to complete
1334 synchronized (request) {
1335 while (request.result == null) {
1336 try {
1337 request.wait();
1338 } catch (InterruptedException e) {
1339 // Do nothing, go back and wait until the request is complete
1340 }
1341 }
1342 }
1343 return request.result;
1344 }
1345
1346 /**
1347 * Asynchronous ("fire and forget") version of sendRequest():
1348 * Posts the specified command to be executed on the main thread, and
1349 * returns immediately.
1350 * @see #sendRequest
1351 */
1352 private void sendRequestAsync(int command) {
1353 mMainThreadHandler.sendEmptyMessage(command);
1354 }
1355
1356 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001357 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001358 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001359 */
1360 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001361 sendRequestAsync(command, argument, null, null);
1362 }
1363
1364 /**
1365 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1366 * @see {@link #sendRequest(int,Object)}
1367 */
1368 private void sendRequestAsync(
1369 int command, Object argument, Phone phone, WorkSource workSource) {
1370 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001371 Message msg = mMainThreadHandler.obtainMessage(command, request);
1372 msg.sendToTarget();
1373 }
1374
1375 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001376 * Initialize the singleton PhoneInterfaceManager instance.
1377 * This is only done once, at startup, from PhoneApp.onCreate().
1378 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001379 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001380 synchronized (PhoneInterfaceManager.class) {
1381 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001382 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001383 } else {
1384 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1385 }
1386 return sInstance;
1387 }
1388 }
1389
1390 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001391 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001392 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001393 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -08001394 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001395 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001396 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1397 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001398 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001399 mTelephonySharedPreferences =
1400 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001401 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001402 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001403
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001404 publish();
1405 }
1406
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001407 private Phone getDefaultPhone() {
1408 Phone thePhone = getPhone(getDefaultSubscription());
1409 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1410 }
1411
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001412 private void publish() {
1413 if (DBG) log("publish: " + this);
1414
1415 ServiceManager.addService("phone", this);
1416 }
1417
Stuart Scott584921c2015-01-15 17:10:34 -08001418 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001419 if (request.phone != null) {
1420 return request.phone;
1421 } else {
1422 return getPhoneFromSubId(request.subId);
1423 }
1424 }
1425
1426 private Phone getPhoneFromSubId(int subId) {
1427 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1428 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001429 }
1430
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001431 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1432 Phone phone = getPhoneFromRequest(request);
1433 return phone == null ? null :
1434 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1435 }
1436
Wink Saville36469e72014-06-11 15:17:00 -07001437 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001438 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001439 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001440 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001441
Naina Nallurid63128d2019-09-17 14:10:30 -07001442 private void sendEraseModemConfig(Phone phone) {
1443 if (phone != null) {
1444 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1445 mApp, phone.getSubId(), "eraseModemConfig");
1446 final long identity = Binder.clearCallingIdentity();
1447 try {
1448 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1449 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1450 } finally {
1451 Binder.restoreCallingIdentity(identity);
1452 }
1453 }
1454 }
1455
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001456 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001457 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001458 }
1459
Wink Savilleb564aae2014-10-23 10:18:09 -07001460 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001461 if (DBG) log("dial: " + number);
1462 // No permission check needed here: This is just a wrapper around the
1463 // ACTION_DIAL intent, which is available to any app since it puts up
1464 // the UI before it does anything.
1465
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001466 final long identity = Binder.clearCallingIdentity();
1467 try {
1468 String url = createTelUrl(number);
1469 if (url == null) {
1470 return;
1471 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001472
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001473 // PENDING: should we just silently fail if phone is offhook or ringing?
1474 PhoneConstants.State state = mCM.getState(subId);
1475 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1476 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1477 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1478 mApp.startActivity(intent);
1479 }
1480 } finally {
1481 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001482 }
1483 }
1484
1485 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001486 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001487 }
1488
Wink Savilleb564aae2014-10-23 10:18:09 -07001489 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001490 if (DBG) log("call: " + number);
1491
1492 // This is just a wrapper around the ACTION_CALL intent, but we still
1493 // need to do a permission check since we're calling startActivity()
1494 // from the context of the phone app.
1495 enforceCallPermission();
1496
Jordan Liu1617b712019-07-10 15:06:26 -07001497 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001498 != AppOpsManager.MODE_ALLOWED) {
1499 return;
1500 }
1501
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001502 final long identity = Binder.clearCallingIdentity();
1503 try {
1504 String url = createTelUrl(number);
1505 if (url == null) {
1506 return;
1507 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001508
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001509 boolean isValid = false;
1510 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1511 if (slist != null) {
1512 for (SubscriptionInfo subInfoRecord : slist) {
1513 if (subInfoRecord.getSubscriptionId() == subId) {
1514 isValid = true;
1515 break;
1516 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001517 }
Wink Saville08874612014-08-31 19:19:58 -07001518 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001519 if (!isValid) {
1520 return;
1521 }
Wink Saville08874612014-08-31 19:19:58 -07001522
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001523 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1524 intent.putExtra(SUBSCRIPTION_KEY, subId);
1525 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1526 mApp.startActivity(intent);
1527 } finally {
1528 Binder.restoreCallingIdentity(identity);
1529 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001530 }
1531
Wink Savilleb564aae2014-10-23 10:18:09 -07001532 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001533 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001534 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1535 }
1536
Wink Savilleb564aae2014-10-23 10:18:09 -07001537 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001538 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001539 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1540 }
1541
Wink Savilleb564aae2014-10-23 10:18:09 -07001542 public int[] supplyPinReportResultForSubscriber(int subId, 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 checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1548 checkSimPin.start();
1549 return checkSimPin.unlockSim(null, pin);
1550 } finally {
1551 Binder.restoreCallingIdentity(identity);
1552 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001553 }
1554
Wink Savilleb564aae2014-10-23 10:18:09 -07001555 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001556 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001557
1558 final long identity = Binder.clearCallingIdentity();
1559 try {
1560 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1561 checkSimPuk.start();
1562 return checkSimPuk.unlockSim(puk, pin);
1563 } finally {
1564 Binder.restoreCallingIdentity(identity);
1565 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001566 }
1567
1568 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001569 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001570 * a synchronous one.
1571 */
1572 private static class UnlockSim extends Thread {
1573
1574 private final IccCard mSimCard;
1575
1576 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001577 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1578 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001579
1580 // For replies from SimCard interface
1581 private Handler mHandler;
1582
1583 // For async handler to identify request type
1584 private static final int SUPPLY_PIN_COMPLETE = 100;
1585
1586 public UnlockSim(IccCard simCard) {
1587 mSimCard = simCard;
1588 }
1589
1590 @Override
1591 public void run() {
1592 Looper.prepare();
1593 synchronized (UnlockSim.this) {
1594 mHandler = new Handler() {
1595 @Override
1596 public void handleMessage(Message msg) {
1597 AsyncResult ar = (AsyncResult) msg.obj;
1598 switch (msg.what) {
1599 case SUPPLY_PIN_COMPLETE:
1600 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1601 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001602 mRetryCount = msg.arg1;
1603 if (ar.exception != null) {
1604 if (ar.exception instanceof CommandException &&
1605 ((CommandException)(ar.exception)).getCommandError()
1606 == CommandException.Error.PASSWORD_INCORRECT) {
1607 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1608 } else {
1609 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1610 }
1611 } else {
1612 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1613 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001614 mDone = true;
1615 UnlockSim.this.notifyAll();
1616 }
1617 break;
1618 }
1619 }
1620 };
1621 UnlockSim.this.notifyAll();
1622 }
1623 Looper.loop();
1624 }
1625
1626 /*
1627 * Use PIN or PUK to unlock SIM card
1628 *
1629 * If PUK is null, unlock SIM card with PIN
1630 *
1631 * If PUK is not null, unlock SIM card with PUK and set PIN code
1632 */
Wink Saville9de0f752013-10-22 19:04:03 -07001633 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001634
1635 while (mHandler == null) {
1636 try {
1637 wait();
1638 } catch (InterruptedException e) {
1639 Thread.currentThread().interrupt();
1640 }
1641 }
1642 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1643
1644 if (puk == null) {
1645 mSimCard.supplyPin(pin, callback);
1646 } else {
1647 mSimCard.supplyPuk(puk, pin, callback);
1648 }
1649
1650 while (!mDone) {
1651 try {
1652 Log.d(LOG_TAG, "wait for done");
1653 wait();
1654 } catch (InterruptedException e) {
1655 // Restore the interrupted status
1656 Thread.currentThread().interrupt();
1657 }
1658 }
1659 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001660 int[] resultArray = new int[2];
1661 resultArray[0] = mResult;
1662 resultArray[1] = mRetryCount;
1663 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001664 }
1665 }
1666
1667 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001668 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001669
1670 }
1671
Wink Savilleb564aae2014-10-23 10:18:09 -07001672 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001673 // No permission check needed here: this call is harmless, and it's
1674 // needed for the ServiceState.requestStateUpdate() call (which is
1675 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001676 final long identity = Binder.clearCallingIdentity();
1677 try {
1678 final Phone phone = getPhone(subId);
1679 if (phone != null) {
1680 phone.updateServiceLocation();
1681 }
1682 } finally {
1683 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001684 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001685 }
1686
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001687 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001688 @Override
1689 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001690 return isRadioOnWithFeature(callingPackage, null);
1691 }
1692
1693
1694 @Override
1695 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
1696 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
1697 callingFeatureId);
1698 }
1699
1700 @Deprecated
1701 @Override
1702 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
1703 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07001704 }
1705
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001706 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001707 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
1708 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001709 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001710 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001711 return false;
1712 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001713
1714 final long identity = Binder.clearCallingIdentity();
1715 try {
1716 return isRadioOnForSubscriber(subId);
1717 } finally {
1718 Binder.restoreCallingIdentity(identity);
1719 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001720 }
1721
1722 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001723 final long identity = Binder.clearCallingIdentity();
1724 try {
1725 final Phone phone = getPhone(subId);
1726 if (phone != null) {
1727 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1728 } else {
1729 return false;
1730 }
1731 } finally {
1732 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001733 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001734 }
1735
1736 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001737 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001738 }
Wink Saville36469e72014-06-11 15:17:00 -07001739
Wink Savilleb564aae2014-10-23 10:18:09 -07001740 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001741 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001742
1743 final long identity = Binder.clearCallingIdentity();
1744 try {
1745 final Phone phone = getPhone(subId);
1746 if (phone != null) {
1747 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1748 }
1749 } finally {
1750 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001751 }
Wink Saville36469e72014-06-11 15:17:00 -07001752 }
1753
1754 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001755 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001756 }
1757
Wink Savilleb564aae2014-10-23 10:18:09 -07001758 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001759 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001760
1761 final long identity = Binder.clearCallingIdentity();
1762 try {
1763 final Phone phone = getPhone(subId);
1764 if (phone == null) {
1765 return false;
1766 }
1767 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1768 toggleRadioOnOffForSubscriber(subId);
1769 }
1770 return true;
1771 } finally {
1772 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001773 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001774 }
Wink Saville36469e72014-06-11 15:17:00 -07001775
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001776 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08001777 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001778 /*
1779 * If any of the Radios are available, it will need to be
1780 * shutdown. So return true if any Radio is available.
1781 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001782 final long identity = Binder.clearCallingIdentity();
1783 try {
1784 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1785 Phone phone = PhoneFactory.getPhone(i);
1786 if (phone != null && phone.isRadioAvailable()) return true;
1787 }
1788 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1789 return false;
1790 } finally {
1791 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001792 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001793 }
1794
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001795 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001796 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001797 enforceModifyPermission();
1798
1799 final long identity = Binder.clearCallingIdentity();
1800 try {
1801 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1802 logv("Shutting down Phone " + i);
1803 shutdownRadioUsingPhoneId(i);
1804 }
1805 } finally {
1806 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001807 }
1808 }
1809
1810 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001811 Phone phone = PhoneFactory.getPhone(phoneId);
1812 if (phone != null && phone.isRadioAvailable()) {
1813 phone.shutdownRadio();
1814 }
1815 }
1816
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001817 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001818 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001819
1820 final long identity = Binder.clearCallingIdentity();
1821 try {
1822 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1823 if (defaultPhone != null) {
1824 defaultPhone.setRadioPower(turnOn);
1825 return true;
1826 } else {
1827 loge("There's no default phone.");
1828 return false;
1829 }
1830 } finally {
1831 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001832 }
Wink Saville36469e72014-06-11 15:17:00 -07001833 }
1834
Wink Savilleb564aae2014-10-23 10:18:09 -07001835 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001836 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001837
1838 final long identity = Binder.clearCallingIdentity();
1839 try {
1840 final Phone phone = getPhone(subId);
1841 if (phone != null) {
1842 phone.setRadioPower(turnOn);
1843 return true;
1844 } else {
1845 return false;
1846 }
1847 } finally {
1848 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001849 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001850 }
1851
Wink Saville36469e72014-06-11 15:17:00 -07001852 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001853 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001854 public boolean enableDataConnectivity() {
1855 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001856
1857 final long identity = Binder.clearCallingIdentity();
1858 try {
1859 int subId = mSubscriptionController.getDefaultDataSubId();
1860 final Phone phone = getPhone(subId);
1861 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001862 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001863 return true;
1864 } else {
1865 return false;
1866 }
1867 } finally {
1868 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001869 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001870 }
1871
Wink Saville36469e72014-06-11 15:17:00 -07001872 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001873 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001874 public boolean disableDataConnectivity() {
1875 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001876
1877 final long identity = Binder.clearCallingIdentity();
1878 try {
1879 int subId = mSubscriptionController.getDefaultDataSubId();
1880 final Phone phone = getPhone(subId);
1881 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001882 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001883 return true;
1884 } else {
1885 return false;
1886 }
1887 } finally {
1888 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001889 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001890 }
1891
Sanket Padawe356d7632015-06-22 14:03:32 -07001892 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001893 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001894 final long identity = Binder.clearCallingIdentity();
1895 try {
1896 final Phone phone = getPhone(subId);
1897 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001898 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001899 } else {
1900 return false;
1901 }
1902 } finally {
1903 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001904 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001905 }
1906
1907 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001908 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001909 }
1910
pkanwarae03a6b2016-11-06 20:37:09 -08001911 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001912 enforceCallPermission();
1913
1914 final long identity = Binder.clearCallingIdentity();
1915 try {
1916 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1917 return;
1918 }
1919 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1920 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1921 } finally {
1922 Binder.restoreCallingIdentity(identity);
1923 }
pkanwar32d516d2016-10-14 19:37:38 -07001924 };
1925
Wink Savilleb564aae2014-10-23 10:18:09 -07001926 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001927 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001928
1929 final long identity = Binder.clearCallingIdentity();
1930 try {
1931 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1932 return false;
1933 }
1934 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1935 } finally {
1936 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001937 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001938 }
1939
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001940 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001941 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001942 }
1943
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001944 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001945 final long identity = Binder.clearCallingIdentity();
1946 try {
1947 Phone phone = PhoneFactory.getPhone(slotIndex);
1948 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1949 PhoneConstantConversions.convertCallState(phone.getState());
1950 } finally {
1951 Binder.restoreCallingIdentity(identity);
1952 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001953 }
1954
Sanket Padawe356d7632015-06-22 14:03:32 -07001955 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001956 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001957 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
1958 }
1959
1960 @Override
1961 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001962 final long identity = Binder.clearCallingIdentity();
1963 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001964 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001965 if (phone != null) {
1966 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1967 } else {
1968 return PhoneConstantConversions.convertDataState(
1969 PhoneConstants.DataState.DISCONNECTED);
1970 }
1971 } finally {
1972 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001973 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001974 }
1975
Sanket Padawe356d7632015-06-22 14:03:32 -07001976 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001977 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001978 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
1979 }
1980
1981 @Override
1982 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001983 final long identity = Binder.clearCallingIdentity();
1984 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001985 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001986 if (phone != null) {
1987 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1988 } else {
1989 return TelephonyManager.DATA_ACTIVITY_NONE;
1990 }
1991 } finally {
1992 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001993 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001994 }
1995
1996 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08001997 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001998 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001999 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002000
2001 LocationAccessPolicy.LocationPermissionResult locationResult =
2002 LocationAccessPolicy.checkLocationPermission(mApp,
2003 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2004 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002005 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002006 .setCallingPid(Binder.getCallingPid())
2007 .setCallingUid(Binder.getCallingUid())
2008 .setMethod("getCellLocation")
2009 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2010 .build());
2011 switch (locationResult) {
2012 case DENIED_HARD:
2013 throw new SecurityException("Not allowed to access cell location");
2014 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002015 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2016 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002017 }
2018
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002019 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002020 final long identity = Binder.clearCallingIdentity();
2021 try {
2022 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002023 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002024 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002025 } finally {
2026 Binder.restoreCallingIdentity(identity);
2027 }
Svetoslav64fad262015-04-14 14:35:21 -07002028 }
2029
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002030 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002031 public String getNetworkCountryIsoForPhone(int phoneId, String callingPackage,
2032 String callingFeatureId) {
Jack Yu1e81ccd2019-09-26 11:48:33 -07002033 if (!TextUtils.isEmpty(callingPackage)) {
2034 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002035 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2036 callingFeatureId, "getNetworkCountryIsoForPhone")) {
Jack Yu1e81ccd2019-09-26 11:48:33 -07002037 return "";
2038 }
2039 }
2040
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002041 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2042 // registered cell info, so return a NULL country instead.
2043 final long identity = Binder.clearCallingIdentity();
2044 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002045 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2046 // Get default phone in this case.
2047 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2048 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002049 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07002050 // Todo: fix this when we can get the actual cellular network info when the device
2051 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002052 if (TelephonyManager.NETWORK_TYPE_IWLAN
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002053 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName(),
2054 mApp.getFeatureId())) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002055 return "";
2056 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002057 Phone phone = PhoneFactory.getPhone(phoneId);
2058 if (phone != null) {
2059 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07002060 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002061 if (sst != null) {
2062 LocaleTracker lt = sst.getLocaleTracker();
2063 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07002064 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
2065 return lt.getCurrentCountry();
2066 } else if (emergencyNumberTracker != null) {
2067 return emergencyNumberTracker.getEmergencyCountryIso();
2068 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002069 }
2070 }
2071 }
2072 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002073 } finally {
2074 Binder.restoreCallingIdentity(identity);
2075 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002076 }
2077
2078 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002079 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002080 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002081 }
2082
Sanket Padawe356d7632015-06-22 14:03:32 -07002083 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002084 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002085 mApp.enforceCallingOrSelfPermission(
2086 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002087
2088 final long identity = Binder.clearCallingIdentity();
2089 try {
2090 final Phone phone = getPhone(subId);
2091 if (phone != null) {
2092 phone.enableLocationUpdates();
2093 }
2094 } finally {
2095 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002096 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002097 }
2098
2099 @Override
2100 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002101 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002102 }
2103
Sanket Padawe356d7632015-06-22 14:03:32 -07002104 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002105 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002106 mApp.enforceCallingOrSelfPermission(
2107 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002108
2109 final long identity = Binder.clearCallingIdentity();
2110 try {
2111 final Phone phone = getPhone(subId);
2112 if (phone != null) {
2113 phone.disableLocationUpdates();
2114 }
2115 } finally {
2116 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002117 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002118 }
2119
Nathan Harold31d7ff32018-10-15 20:20:30 -07002120 /**
2121 * Returns the target SDK version number for a given package name.
2122 *
Nathan Haroldec184742019-07-10 17:04:16 -07002123 * This call MUST be invoked before clearing the calling UID.
2124 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002125 * @return target SDK if the package is found or INT_MAX.
2126 */
2127 private int getTargetSdk(String packageName) {
2128 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002129 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu0150f0e2019-07-30 15:12:06 -07002130 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002131 if (ai != null) return ai.targetSdkVersion;
2132 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002133 loge("Failed to get package info for pkg="
2134 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002135 }
2136 return Integer.MAX_VALUE;
2137 }
2138
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002139 @Override
2140 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002141 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2142 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002143 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002144 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2145 throw new SecurityException(
2146 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2147 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002148
Jordan Liu1617b712019-07-10 15:06:26 -07002149 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002150 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2151 return null;
2152 }
Svetoslav64fad262015-04-14 14:35:21 -07002153
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002154 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002155
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002156 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002157 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002158
Nathan Haroldf180aac2018-06-01 18:43:55 -07002159 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2160 for (CellInfo ci : info) {
2161 if (ci instanceof CellInfoGsm) {
2162 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2163 } else if (ci instanceof CellInfoWcdma) {
2164 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2165 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002166 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002167 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002168 }
2169
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002170 private List<CellInfo> getCachedCellInfo() {
2171 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2172 for (Phone phone : PhoneFactory.getPhones()) {
2173 List<CellInfo> info = phone.getAllCellInfo();
2174 if (info != null) cellInfos.addAll(info);
2175 }
2176 return cellInfos;
2177 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002178
2179 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002180 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002181 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002182 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002183
2184 LocationAccessPolicy.LocationPermissionResult locationResult =
2185 LocationAccessPolicy.checkLocationPermission(mApp,
2186 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2187 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002188 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002189 .setCallingPid(Binder.getCallingPid())
2190 .setCallingUid(Binder.getCallingUid())
2191 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002192 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002193 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2194 .build());
2195 switch (locationResult) {
2196 case DENIED_HARD:
2197 throw new SecurityException("Not allowed to access cell info");
2198 case DENIED_SOFT:
2199 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002200 }
2201
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002202 final int targetSdk = getTargetSdk(callingPackage);
2203 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2204 return getCachedCellInfo();
2205 }
2206
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002207 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002208 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002209 final long identity = Binder.clearCallingIdentity();
2210 try {
2211 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2212 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002213 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002214 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002215 if (info != null) cellInfos.addAll(info);
2216 }
2217 return cellInfos;
2218 } finally {
2219 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002220 }
2221 }
2222
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002223 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002224 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2225 String callingFeatureId) {
2226 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2227 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002228 }
2229
2230 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002231 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2232 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002233 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002234 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002235 }
2236
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002237 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2238 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002239 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002240 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002241
2242 LocationAccessPolicy.LocationPermissionResult locationResult =
2243 LocationAccessPolicy.checkLocationPermission(mApp,
2244 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2245 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002246 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002247 .setCallingPid(Binder.getCallingPid())
2248 .setCallingUid(Binder.getCallingUid())
2249 .setMethod("requestCellInfoUpdate")
2250 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2251 .build());
2252 switch (locationResult) {
2253 case DENIED_HARD:
2254 throw new SecurityException("Not allowed to access cell info");
2255 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002256 try {
2257 cb.onCellInfo(new ArrayList<CellInfo>());
2258 } catch (RemoteException re) {
2259 // Drop without consequences
2260 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002261 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002262 }
2263
Nathan Harolda939a962019-05-09 10:13:47 -07002264
2265 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002266 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2267
2268 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2269 }
2270
2271 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002272 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002273 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002274 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002275
2276 final long identity = Binder.clearCallingIdentity();
2277 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002278 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002279 } finally {
2280 Binder.restoreCallingIdentity(identity);
2281 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002282 }
2283
Shishir Agrawala9f32182016-04-12 12:00:16 -07002284 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002285 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002286 Phone phone = PhoneFactory.getPhone(slotIndex);
2287 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002288 return null;
2289 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002290 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002291 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002292 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002293 return null;
2294 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002295
2296 final long identity = Binder.clearCallingIdentity();
2297 try {
2298 return phone.getImei();
2299 } finally {
2300 Binder.restoreCallingIdentity(identity);
2301 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002302 }
2303
2304 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002305 public String getTypeAllocationCodeForSlot(int slotIndex) {
2306 Phone phone = PhoneFactory.getPhone(slotIndex);
2307 String tac = null;
2308 if (phone != null) {
2309 String imei = phone.getImei();
2310 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2311 }
2312 return tac;
2313 }
2314
2315 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002316 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002317 Phone phone = PhoneFactory.getPhone(slotIndex);
2318 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002319 return null;
2320 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002321
Jeff Davidson913390f2018-02-23 17:11:49 -08002322 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002323 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002324 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002325 return null;
2326 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002327
2328 final long identity = Binder.clearCallingIdentity();
2329 try {
2330 return phone.getMeid();
2331 } finally {
2332 Binder.restoreCallingIdentity(identity);
2333 }
Jack Yu2af8d712017-03-15 17:14:14 -07002334 }
2335
2336 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002337 public String getManufacturerCodeForSlot(int slotIndex) {
2338 Phone phone = PhoneFactory.getPhone(slotIndex);
2339 String manufacturerCode = null;
2340 if (phone != null) {
2341 String meid = phone.getMeid();
2342 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2343 }
2344 return manufacturerCode;
2345 }
2346
2347 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002348 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2349 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002350 Phone phone = PhoneFactory.getPhone(slotIndex);
2351 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002352 return null;
2353 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002354 int subId = phone.getSubId();
2355 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002356 mApp, subId, callingPackage, callingFeatureId,
2357 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002358 return null;
2359 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002360
2361 final long identity = Binder.clearCallingIdentity();
2362 try {
2363 return phone.getDeviceSvn();
2364 } finally {
2365 Binder.restoreCallingIdentity(identity);
2366 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002367 }
2368
fionaxu43304da2017-11-27 22:51:16 -08002369 @Override
2370 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002371 final long identity = Binder.clearCallingIdentity();
2372 try {
2373 final Phone phone = getPhone(subId);
2374 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2375 } finally {
2376 Binder.restoreCallingIdentity(identity);
2377 }
fionaxu43304da2017-11-27 22:51:16 -08002378 }
2379
2380 @Override
2381 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002382 final long identity = Binder.clearCallingIdentity();
2383 try {
2384 final Phone phone = getPhone(subId);
2385 return phone == null ? null : phone.getCarrierName();
2386 } finally {
2387 Binder.restoreCallingIdentity(identity);
2388 }
fionaxu43304da2017-11-27 22:51:16 -08002389 }
2390
calvinpanffe225e2018-11-01 19:43:06 +08002391 @Override
chen xu0026ca62019-03-06 15:28:50 -08002392 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002393 final long identity = Binder.clearCallingIdentity();
2394 try {
2395 final Phone phone = getPhone(subId);
2396 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002397 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002398 } finally {
2399 Binder.restoreCallingIdentity(identity);
2400 }
2401 }
2402
2403 @Override
chen xu0026ca62019-03-06 15:28:50 -08002404 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002405 final long identity = Binder.clearCallingIdentity();
2406 try {
2407 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002408 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002409 } finally {
2410 Binder.restoreCallingIdentity(identity);
2411 }
2412 }
2413
chen xu651eec72018-11-11 19:03:44 -08002414 @Override
chen xu864e11c2018-12-06 22:10:03 -08002415 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2416 if (!isSubscriptionMccMnc) {
2417 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2418 }
chen xu651eec72018-11-11 19:03:44 -08002419 final Phone phone = PhoneFactory.getPhone(slotIndex);
2420 if (phone == null) {
2421 return TelephonyManager.UNKNOWN_CARRIER_ID;
2422 }
2423 final long identity = Binder.clearCallingIdentity();
2424 try {
2425 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2426 } finally {
2427 Binder.restoreCallingIdentity(identity);
2428 }
2429 }
2430
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002431 //
2432 // Internal helper methods.
2433 //
2434
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002435 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002436 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2437 *
2438 * @throws SecurityException if the caller does not have the required permission
2439 */
2440 private void enforceModifyPermission() {
2441 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2442 }
2443
Shuo Qian3b6ee772019-11-13 17:43:31 -08002444 private void enforceActiveEmergencySessionPermission() {
2445 mApp.enforceCallingOrSelfPermission(
2446 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2447 }
2448
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002449 /**
2450 * Make sure the caller has the CALL_PHONE permission.
2451 *
2452 * @throws SecurityException if the caller does not have the required permission
2453 */
2454 private void enforceCallPermission() {
2455 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2456 }
2457
paulhu5a773602019-08-23 19:17:33 +08002458 private void enforceSettingsPermission() {
2459 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002460 }
2461
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002462 private String createTelUrl(String number) {
2463 if (TextUtils.isEmpty(number)) {
2464 return null;
2465 }
2466
Jake Hambye994d462014-02-03 13:10:13 -08002467 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002468 }
2469
Ihab Awadf9e92732013-12-05 18:02:52 -08002470 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002471 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2472 }
2473
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002474 private static void logv(String msg) {
2475 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2476 }
2477
Ihab Awadf9e92732013-12-05 18:02:52 -08002478 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002479 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2480 }
2481
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002482 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002483 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002484 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002485 }
2486
Sanket Padawe356d7632015-06-22 14:03:32 -07002487 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002488 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002489 final long identity = Binder.clearCallingIdentity();
2490 try {
2491 final Phone phone = PhoneFactory.getPhone(slotIndex);
2492 if (phone == null) {
2493 return PhoneConstants.PHONE_TYPE_NONE;
2494 } else {
2495 return phone.getPhoneType();
2496 }
2497 } finally {
2498 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002499 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002500 }
2501
2502 /**
2503 * Returns the CDMA ERI icon index to display
2504 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002505 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002506 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2507 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2508 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002509 }
2510
Sanket Padawe356d7632015-06-22 14:03:32 -07002511 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002512 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2513 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002514 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002515 mApp, subId, callingPackage, callingFeatureId,
2516 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002517 return -1;
2518 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002519
2520 final long identity = Binder.clearCallingIdentity();
2521 try {
2522 final Phone phone = getPhone(subId);
2523 if (phone != null) {
2524 return phone.getCdmaEriIconIndex();
2525 } else {
2526 return -1;
2527 }
2528 } finally {
2529 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002530 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002531 }
2532
2533 /**
2534 * Returns the CDMA ERI icon mode,
2535 * 0 - ON
2536 * 1 - FLASHING
2537 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002538 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002539 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2540 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2541 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002542 }
2543
Sanket Padawe356d7632015-06-22 14:03:32 -07002544 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002545 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2546 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002547 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002548 mApp, subId, callingPackage, callingFeatureId,
2549 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002550 return -1;
2551 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002552
2553 final long identity = Binder.clearCallingIdentity();
2554 try {
2555 final Phone phone = getPhone(subId);
2556 if (phone != null) {
2557 return phone.getCdmaEriIconMode();
2558 } else {
2559 return -1;
2560 }
2561 } finally {
2562 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002563 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002564 }
2565
2566 /**
2567 * Returns the CDMA ERI text,
2568 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002569 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002570 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
2571 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
2572 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002573 }
2574
Sanket Padawe356d7632015-06-22 14:03:32 -07002575 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002576 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
2577 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002578 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002579 mApp, subId, callingPackage, callingFeatureId,
2580 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002581 return null;
2582 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002583
2584 final long identity = Binder.clearCallingIdentity();
2585 try {
2586 final Phone phone = getPhone(subId);
2587 if (phone != null) {
2588 return phone.getCdmaEriText();
2589 } else {
2590 return null;
2591 }
2592 } finally {
2593 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002594 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002595 }
2596
2597 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002598 * Returns the CDMA MDN.
2599 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002600 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002601 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002602 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2603 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002604
2605 final long identity = Binder.clearCallingIdentity();
2606 try {
2607 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002608 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002609 return phone.getLine1Number();
2610 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002611 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002612 return null;
2613 }
2614 } finally {
2615 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002616 }
2617 }
2618
2619 /**
2620 * Returns the CDMA MIN.
2621 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002622 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002623 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002624 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2625 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002626
2627 final long identity = Binder.clearCallingIdentity();
2628 try {
2629 final Phone phone = getPhone(subId);
2630 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2631 return phone.getCdmaMin();
2632 } else {
2633 return null;
2634 }
2635 } finally {
2636 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002637 }
2638 }
2639
Hall Liud892bec2018-11-30 14:51:45 -08002640 @Override
2641 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2642 INumberVerificationCallback callback, String callingPackage) {
2643 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2644 != PERMISSION_GRANTED) {
2645 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2646 }
2647 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2648
2649 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2650 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2651 throw new SecurityException("Calling package must be configured in the device config");
2652 }
2653
2654 if (range == null) {
2655 throw new NullPointerException("Range must be non-null");
2656 }
2657
2658 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002659 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002660
2661 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2662 }
2663
Junda Liuca05d5d2014-08-14 22:36:34 -07002664 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002665 * Returns true if CDMA provisioning needs to run.
2666 */
2667 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002668 final long identity = Binder.clearCallingIdentity();
2669 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002670 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002671 } finally {
2672 Binder.restoreCallingIdentity(identity);
2673 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002674 }
2675
2676 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002677 * Sets the voice mail number of a given subId.
2678 */
2679 @Override
2680 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08002681 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2682 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002683
2684 final long identity = Binder.clearCallingIdentity();
2685 try {
2686 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2687 new Pair<String, String>(alphaTag, number), new Integer(subId));
2688 return success;
2689 } finally {
2690 Binder.restoreCallingIdentity(identity);
2691 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002692 }
2693
Ta-wei Yen87c49842016-05-13 21:19:52 -07002694 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002695 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2696 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07002697 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2698 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002699 if (!TextUtils.equals(callingPackage, systemDialer)) {
2700 throw new SecurityException("caller must be system dialer");
2701 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002702
2703 final long identity = Binder.clearCallingIdentity();
2704 try {
2705 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2706 if (phoneAccountHandle == null) {
2707 return null;
2708 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002709 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002710 } finally {
2711 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002712 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002713 }
2714
2715 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002716 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
2717 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002718 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002719 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002720 mApp, subId, callingPackage, callingFeatureId,
2721 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002722 return null;
2723 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002724
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002725 final long identity = Binder.clearCallingIdentity();
2726 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002727 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002728 } finally {
2729 Binder.restoreCallingIdentity(identity);
2730 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002731 }
2732
2733 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002734 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2735 VisualVoicemailSmsFilterSettings settings) {
2736 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002737
2738 final long identity = Binder.clearCallingIdentity();
2739 try {
2740 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002741 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002742 } finally {
2743 Binder.restoreCallingIdentity(identity);
2744 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002745 }
2746
2747 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002748 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2749 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002750
2751 final long identity = Binder.clearCallingIdentity();
2752 try {
2753 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002754 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002755 } finally {
2756 Binder.restoreCallingIdentity(identity);
2757 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002758 }
2759
2760 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002761 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2762 String callingPackage, int subId) {
2763 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002764
2765 final long identity = Binder.clearCallingIdentity();
2766 try {
2767 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002768 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002769 } finally {
2770 Binder.restoreCallingIdentity(identity);
2771 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002772 }
2773
2774 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002775 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002776 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002777
2778 final long identity = Binder.clearCallingIdentity();
2779 try {
2780 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002781 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002782 } finally {
2783 Binder.restoreCallingIdentity(identity);
2784 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002785 }
2786
2787 @Override
2788 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2789 String number, int port, String text, PendingIntent sentIntent) {
2790 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002791 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002792 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07002793 SmsController smsController = PhoneFactory.getSmsController();
2794 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
2795 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002796 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07002797
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002798 /**
fionaxu0152e512016-11-14 13:36:14 -08002799 * Sets the voice activation state of a given subId.
2800 */
2801 @Override
2802 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002803 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2804 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002805
2806 final long identity = Binder.clearCallingIdentity();
2807 try {
2808 final Phone phone = getPhone(subId);
2809 if (phone != null) {
2810 phone.setVoiceActivationState(activationState);
2811 } else {
2812 loge("setVoiceActivationState fails with invalid subId: " + subId);
2813 }
2814 } finally {
2815 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002816 }
2817 }
2818
2819 /**
2820 * Sets the data activation state of a given subId.
2821 */
2822 @Override
2823 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002824 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2825 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002826
2827 final long identity = Binder.clearCallingIdentity();
2828 try {
2829 final Phone phone = getPhone(subId);
2830 if (phone != null) {
2831 phone.setDataActivationState(activationState);
2832 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09002833 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002834 }
2835 } finally {
2836 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002837 }
2838 }
2839
2840 /**
2841 * Returns the voice activation state of a given subId.
2842 */
2843 @Override
2844 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002845 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002846
fionaxu0152e512016-11-14 13:36:14 -08002847 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002848 final long identity = Binder.clearCallingIdentity();
2849 try {
2850 if (phone != null) {
2851 return phone.getVoiceActivationState();
2852 } else {
2853 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2854 }
2855 } finally {
2856 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002857 }
2858 }
2859
2860 /**
2861 * Returns the data activation state of a given subId.
2862 */
2863 @Override
2864 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002865 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002866
fionaxu0152e512016-11-14 13:36:14 -08002867 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002868 final long identity = Binder.clearCallingIdentity();
2869 try {
2870 if (phone != null) {
2871 return phone.getDataActivationState();
2872 } else {
2873 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2874 }
2875 } finally {
2876 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002877 }
2878 }
2879
2880 /**
Wink Saville36469e72014-06-11 15:17:00 -07002881 * Returns the unread count of voicemails for a subId
2882 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002883 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002884 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
2885 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002886 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002887 mApp, subId, callingPackage, callingFeatureId,
2888 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002889 return 0;
2890 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002891 final long identity = Binder.clearCallingIdentity();
2892 try {
2893 final Phone phone = getPhone(subId);
2894 if (phone != null) {
2895 return phone.getVoiceMessageCount();
2896 } else {
2897 return 0;
2898 }
2899 } finally {
2900 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002901 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002902 }
2903
2904 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002905 * returns true, if the device is in a state where both voice and data
2906 * are supported simultaneously. This can change based on location or network condition.
2907 */
2908 @Override
2909 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002910 final long identity = Binder.clearCallingIdentity();
2911 try {
2912 final Phone phone = getPhone(subId);
2913 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2914 } finally {
2915 Binder.restoreCallingIdentity(identity);
2916 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002917 }
2918
2919 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002920 * Send the dialer code if called from the current default dialer or the caller has
2921 * carrier privilege.
2922 * @param inputCode The dialer code to send
2923 */
2924 @Override
2925 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002926 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002927 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07002928 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
2929 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002930 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08002931 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08002932 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002933 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002934
2935 final long identity = Binder.clearCallingIdentity();
2936 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002937 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002938 } finally {
2939 Binder.restoreCallingIdentity(identity);
2940 }
fionaxu235cc5e2017-03-06 22:25:57 -08002941 }
2942
Pengquan Menga1bb6272018-09-06 09:59:22 -07002943 @Override
2944 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002945 if (!isActiveSubscription(subId)) {
2946 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2947 }
2948
Pengquan Menga1bb6272018-09-06 09:59:22 -07002949 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2950 }
2951
Brad Ebinger35c841c2018-10-01 10:40:55 -07002952 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002953 public boolean isInEmergencySmsMode() {
2954 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2955 final long identity = Binder.clearCallingIdentity();
2956 try {
2957 for (Phone phone : PhoneFactory.getPhones()) {
2958 if (phone.isInEmergencySmsMode()) {
2959 return true;
2960 }
2961 }
2962 } finally {
2963 Binder.restoreCallingIdentity(identity);
2964 }
2965 return false;
2966 }
2967
2968 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002969 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2970 throws RemoteException {
2971 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07002972 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
2973 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
2974 "IMS not available on device.");
2975 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002976 final long token = Binder.clearCallingIdentity();
2977 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002978 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002979 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002980 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002981 } catch (ImsException e) {
2982 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002983 } finally {
2984 Binder.restoreCallingIdentity(token);
2985 }
2986 }
2987
2988 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002989 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2990 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002991 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2992 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2993 }
Meng Wangafbc5852019-09-19 17:37:13 -07002994 final long token = Binder.clearCallingIdentity();
2995 try {
2996 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
2997 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
2998 .removeRegistrationCallbackForSubscription(c, subId);
2999 } catch (ImsException e) {
3000 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3001 + "is inactive, ignoring unregister.");
3002 // If the subscription is no longer active, just return, since the callback
3003 // will already have been removed internally.
3004 } finally {
3005 Binder.restoreCallingIdentity(token);
3006 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003007 }
3008
Brad Ebingera34a6c22019-10-22 17:36:18 -07003009 /**
3010 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3011 */
3012 @Override
3013 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3014 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3015 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3016 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3017 "IMS not available on device.");
3018 }
3019 final long token = Binder.clearCallingIdentity();
3020 try {
3021 Phone phone = getPhone(subId);
3022 if (phone == null) {
3023 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3024 + subId + "'");
3025 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3026 }
3027 phone.getImsRegistrationState(regState -> {
3028 try {
3029 consumer.accept((regState == null)
3030 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3031 } catch (RemoteException e) {
3032 // Ignore if the remote process is no longer available to call back.
3033 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3034 }
3035 });
3036 } finally {
3037 Binder.restoreCallingIdentity(token);
3038 }
3039 }
3040
3041 /**
3042 * Get the transport type for the IMS service registration state.
3043 */
3044 @Override
3045 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
3046 enforceReadPrivilegedPermission("getImsMmTelRegistrationTransportType");
3047 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3048 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3049 "IMS not available on device.");
3050 }
3051 final long token = Binder.clearCallingIdentity();
3052 try {
3053 Phone phone = getPhone(subId);
3054 if (phone == null) {
3055 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3056 + subId + "'");
3057 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3058 }
3059 phone.getImsRegistrationTech(regTech -> {
3060 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3061 int regTechConverted = (regTech == null)
3062 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3063 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3064 regTechConverted);
3065 try {
3066 consumer.accept(regTechConverted);
3067 } catch (RemoteException e) {
3068 // Ignore if the remote process is no longer available to call back.
3069 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3070 }
3071 });
3072 } finally {
3073 Binder.restoreCallingIdentity(token);
3074 }
3075 }
3076
Brad Ebinger35c841c2018-10-01 10:40:55 -07003077 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003078 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3079 throws RemoteException {
3080 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003081 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3082 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3083 "IMS not available on device.");
3084 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003085 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3086 final long token = Binder.clearCallingIdentity();
3087 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003088 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003089 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003090 } catch (ImsException e) {
3091 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003092 } finally {
3093 Binder.restoreCallingIdentity(token);
3094 }
3095 }
3096
3097 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003098 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
3099 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003100 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3101 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3102 }
Meng Wangafbc5852019-09-19 17:37:13 -07003103
3104 final long token = Binder.clearCallingIdentity();
3105 try {
3106 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3107 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003108 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003109 } catch (ImsException e) {
3110 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3111 + "is inactive, ignoring unregister.");
3112 // If the subscription is no longer active, just return, since the callback
3113 // will already have been removed internally.
3114 } finally {
3115 Binder.restoreCallingIdentity(token);
3116 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003117 }
3118
3119 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003120 public boolean isCapable(int subId, int capability, int regTech) {
3121 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003122 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3123 final long token = Binder.clearCallingIdentity();
3124 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003125 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003126 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003127 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003128 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3129 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003130 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003131 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3132 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003133 } finally {
3134 Binder.restoreCallingIdentity(token);
3135 }
3136 }
3137
3138 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003139 public boolean isAvailable(int subId, int capability, int regTech) {
3140 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003141 final long token = Binder.clearCallingIdentity();
3142 try {
3143 Phone phone = getPhone(subId);
3144 if (phone == null) return false;
3145 return phone.isImsCapabilityAvailable(capability, regTech);
3146 } finally {
3147 Binder.restoreCallingIdentity(token);
3148 }
3149 }
3150
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003151 /**
3152 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3153 * subscription.
3154 * @param subId The subscription to use to check the configuration.
3155 * @param callback The callback that will be used to send the result.
3156 * @param capability The MmTelFeature capability that will be used to send the result.
3157 * @param transportType The transport type of the MmTelFeature capability.
3158 */
3159 @Override
3160 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3161 int transportType) {
3162 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3163 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3164 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3165 "IMS not available on device.");
3166 }
3167 final long token = Binder.clearCallingIdentity();
3168 try {
3169 int slotId = getSlotIndex(subId);
3170 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3171 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3172 + subId + "'");
3173 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3174 }
3175 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3176 transportType, aBoolean -> {
3177 try {
3178 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3179 } catch (RemoteException e) {
3180 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3181 + "running. Ignore");
3182 }
3183 });
3184 } finally {
3185 Binder.restoreCallingIdentity(token);
3186 }
3187 }
3188
Brad Ebinger35c841c2018-10-01 10:40:55 -07003189 @Override
3190 public boolean isAdvancedCallingSettingEnabled(int subId) {
3191 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
3192 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3193 final long token = Binder.clearCallingIdentity();
3194 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003195 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003196 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003197 } catch (ImsException e) {
3198 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003199 } finally {
3200 Binder.restoreCallingIdentity(token);
3201 }
3202 }
3203
3204 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003205 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003206 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003207 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003208 final long identity = Binder.clearCallingIdentity();
3209 try {
3210 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003211 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003212 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003213 } catch (ImsException e) {
3214 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003215 } finally {
3216 Binder.restoreCallingIdentity(identity);
3217 }
3218 }
3219
3220 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003221 public boolean isVtSettingEnabled(int subId) {
3222 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003223 final long identity = Binder.clearCallingIdentity();
3224 try {
3225 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003226 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3227 } catch (ImsException e) {
3228 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003229 } finally {
3230 Binder.restoreCallingIdentity(identity);
3231 }
3232 }
3233
3234 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003235 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003236 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003237 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003238 final long identity = Binder.clearCallingIdentity();
3239 try {
3240 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003241 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003242 } catch (ImsException e) {
3243 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003244 } finally {
3245 Binder.restoreCallingIdentity(identity);
3246 }
3247 }
3248
3249 @Override
3250 public boolean isVoWiFiSettingEnabled(int subId) {
3251 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3252 final long identity = Binder.clearCallingIdentity();
3253 try {
3254 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003255 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003256 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003257 } catch (ImsException e) {
3258 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003259 } finally {
3260 Binder.restoreCallingIdentity(identity);
3261 }
3262 }
3263
3264 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003265 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003266 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003267 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003268 final long identity = Binder.clearCallingIdentity();
3269 try {
3270 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003271 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003272 } catch (ImsException e) {
3273 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003274 } finally {
3275 Binder.restoreCallingIdentity(identity);
3276 }
3277 }
3278
3279 @Override
3280 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3281 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3282 final long identity = Binder.clearCallingIdentity();
3283 try {
3284 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003285 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003286 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003287 } catch (ImsException e) {
3288 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003289 } finally {
3290 Binder.restoreCallingIdentity(identity);
3291 }
3292 }
3293
3294 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003295 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003296 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003297 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003298 final long identity = Binder.clearCallingIdentity();
3299 try {
3300 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003301 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003302 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003303 } catch (ImsException e) {
3304 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003305 } finally {
3306 Binder.restoreCallingIdentity(identity);
3307 }
3308 }
3309
3310 @Override
3311 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3312 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3313 "setVoWiFiNonPersistent");
3314 final long identity = Binder.clearCallingIdentity();
3315 try {
3316 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003317 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003318 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003319 } catch (ImsException e) {
3320 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003321 } finally {
3322 Binder.restoreCallingIdentity(identity);
3323 }
3324 }
3325
3326 @Override
3327 public int getVoWiFiModeSetting(int subId) {
3328 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3329 final long identity = Binder.clearCallingIdentity();
3330 try {
3331 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003332 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003333 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003334 } catch (ImsException e) {
3335 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003336 } finally {
3337 Binder.restoreCallingIdentity(identity);
3338 }
3339 }
3340
3341 @Override
3342 public void setVoWiFiModeSetting(int subId, int mode) {
3343 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3344 "setVoWiFiModeSetting");
3345 final long identity = Binder.clearCallingIdentity();
3346 try {
3347 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003348 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003349 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003350 } catch (ImsException e) {
3351 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003352 } finally {
3353 Binder.restoreCallingIdentity(identity);
3354 }
3355 }
3356
3357 @Override
3358 public int getVoWiFiRoamingModeSetting(int subId) {
3359 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3360 final long identity = Binder.clearCallingIdentity();
3361 try {
3362 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003363 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003364 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003365 } catch (ImsException e) {
3366 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003367 } finally {
3368 Binder.restoreCallingIdentity(identity);
3369 }
3370 }
3371
3372 @Override
3373 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3374 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3375 "setVoWiFiRoamingModeSetting");
3376 final long identity = Binder.clearCallingIdentity();
3377 try {
3378 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003379 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003380 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003381 } catch (ImsException e) {
3382 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003383 } finally {
3384 Binder.restoreCallingIdentity(identity);
3385 }
3386 }
3387
3388 @Override
3389 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3390 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3391 "setRttCapabilityEnabled");
3392 final long identity = Binder.clearCallingIdentity();
3393 try {
3394 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003395 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3396 } catch (ImsException e) {
3397 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003398 } finally {
3399 Binder.restoreCallingIdentity(identity);
3400 }
3401 }
3402
3403 @Override
3404 public boolean isTtyOverVolteEnabled(int subId) {
3405 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3406 final long identity = Binder.clearCallingIdentity();
3407 try {
3408 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003409 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003410 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003411 } catch (ImsException e) {
3412 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003413 } finally {
3414 Binder.restoreCallingIdentity(identity);
3415 }
3416 }
3417
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003418 @Override
3419 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3420 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3421 final long identity = Binder.clearCallingIdentity();
3422 try {
3423 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003424 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003425 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003426 } catch (ImsException e) {
3427 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003428 } finally {
3429 Binder.restoreCallingIdentity(identity);
3430 }
3431 }
3432
3433 @Override
3434 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3435 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3436 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003437 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3438 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3439 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003440 try {
3441 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003442 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003443 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003444 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003445 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3446 + "is inactive, ignoring unregister.");
3447 // If the subscription is no longer active, just return, since the callback will already
3448 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003449 } finally {
3450 Binder.restoreCallingIdentity(identity);
3451 }
3452 }
3453
3454 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003455 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3456 boolean isProvisioned) {
3457 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3458 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3459 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3460 }
3461 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3462 "setProvisioningStatusForCapability");
3463 final long identity = Binder.clearCallingIdentity();
3464 try {
3465 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3466 Phone phone = getPhone(subId);
3467 if (phone == null) {
3468 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3469 + subId);
3470 return;
3471 }
3472 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3473 return;
3474 }
3475
3476 // this capability requires provisioning, route to the correct API.
3477 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3478 switch (capability) {
3479 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3480 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3481 ims.setVolteProvisioned(isProvisioned);
3482 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3483 ims.setWfcProvisioned(isProvisioned);
3484 }
3485 break;
3486 }
3487 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3488 // There is currently no difference in VT provisioning type.
3489 ims.setVtProvisioned(isProvisioned);
3490 break;
3491 }
3492 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3493 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3494 // change the capability of the feature instead if needed.
3495 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3496 == isProvisioned) {
3497 // No change in provisioning.
3498 return;
3499 }
3500 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3501 try {
3502 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003503 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003504 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3505 + ", Exception" + e.getMessage());
3506 }
3507 break;
3508 }
3509 default: {
3510 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3511 + capability + "', which does not require provisioning.");
3512 }
3513 }
3514
3515 } finally {
3516 Binder.restoreCallingIdentity(identity);
3517 }
3518 }
3519
3520 @Override
3521 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3522 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3523 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3524 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3525 }
3526 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3527 final long identity = Binder.clearCallingIdentity();
3528 try {
3529 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3530 Phone phone = getPhone(subId);
3531 if (phone == null) {
3532 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3533 + subId);
3534 // We will fail with "true" as the provisioning status because this is the default
3535 // if we do not require provisioning.
3536 return true;
3537 }
3538
3539 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3540 return true;
3541 }
3542
3543 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3544 switch (capability) {
3545 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3546 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3547 return ims.isVolteProvisionedOnDevice();
3548 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3549 return ims.isWfcProvisionedOnDevice();
3550 }
3551 // This should never happen, since we are checking tech above to make sure it
3552 // is either LTE or IWLAN.
3553 throw new IllegalArgumentException("Invalid radio technology for voice "
3554 + "capability.");
3555 }
3556 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3557 // There is currently no difference in VT provisioning type.
3558 return ims.isVtProvisionedOnDevice();
3559 }
3560 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3561 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3562 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3563 }
3564 default: {
3565 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3566 + capability + "', which does not require provisioning.");
3567 }
3568 }
3569
3570 } finally {
3571 Binder.restoreCallingIdentity(identity);
3572 }
3573 }
3574
3575 @Override
3576 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3577 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3578 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3579 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3580 }
3581 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3582 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3583 return (provisionedBits & capability) > 0;
3584 }
3585
3586 @Override
3587 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3588 boolean isProvisioned) {
3589 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3590 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3591 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3592 }
3593 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3594 "setProvisioningStatusForCapability");
3595 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3596 // If the current provisioning status for capability already matches isProvisioned,
3597 // do nothing.
3598 if (((provisionedBits & capability) > 0) == isProvisioned) {
3599 return;
3600 }
3601 if (isProvisioned) {
3602 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3603 } else {
3604 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3605 }
3606 }
3607
3608 /**
3609 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3610 * technology. The bitfield should mirror the bitfield defined by
3611 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3612 */
3613 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3614 String key = getMmTelProvisioningKey(subId, tech);
3615 // Default is no capabilities are provisioned.
3616 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3617 }
3618
3619 /**
3620 * Sets the MmTel capability provisioning bitfield (defined by
3621 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3622 * technology specified.
3623 *
3624 * Note: This is a synchronous command and should not be called on UI thread.
3625 */
3626 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3627 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3628 String key = getMmTelProvisioningKey(subId, tech);
3629 editor.putInt(key, newField);
3630 editor.commit();
3631 }
3632
3633 private static String getMmTelProvisioningKey(int subId, int tech) {
3634 // resulting key is provision_ims_mmtel_{subId}_{tech}
3635 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3636 }
3637
3638 /**
3639 * Query CarrierConfig to see if the specified capability requires provisioning for the
3640 * carrier associated with the subscription id.
3641 */
3642 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3643 int capability) {
3644 CarrierConfigManager configManager = new CarrierConfigManager(context);
3645 PersistableBundle c = configManager.getConfigForSubId(subId);
3646 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07003647 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003648 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3649 false);
3650 boolean requireVoiceVtProvisioning = c.getBoolean(
3651 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3652
3653 // First check to make sure that the capability requires provisioning.
3654 switch (capability) {
3655 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3656 // intentional fallthrough
3657 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3658 if (requireVoiceVtProvisioning) {
3659 // Voice and Video requires provisioning
3660 return true;
3661 }
3662 break;
3663 }
3664 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3665 if (requireUtProvisioning) {
3666 // UT requires provisioning
3667 return true;
3668 }
3669 break;
3670 }
3671 }
3672 return false;
3673 }
3674
3675 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003676 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003677 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3678 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3679 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003680 enforceReadPrivilegedPermission("getImsProvisioningInt");
3681 final long identity = Binder.clearCallingIdentity();
3682 try {
3683 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003684 int slotId = getSlotIndex(subId);
3685 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3686 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3687 + subId + "' for key:" + key);
3688 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3689 }
3690 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003691 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003692 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3693 + subId + "' for key:" + key);
3694 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003695 } finally {
3696 Binder.restoreCallingIdentity(identity);
3697 }
3698 }
3699
3700 @Override
3701 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003702 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3703 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3704 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003705 enforceReadPrivilegedPermission("getImsProvisioningString");
3706 final long identity = Binder.clearCallingIdentity();
3707 try {
3708 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003709 int slotId = getSlotIndex(subId);
3710 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3711 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3712 + subId + "' for key:" + key);
3713 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3714 }
3715 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003716 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003717 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3718 + subId + "' for key:" + key);
3719 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003720 } finally {
3721 Binder.restoreCallingIdentity(identity);
3722 }
3723 }
3724
3725 @Override
3726 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003727 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3728 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3729 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003730 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3731 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003732 final long identity = Binder.clearCallingIdentity();
3733 try {
3734 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003735 int slotId = getSlotIndex(subId);
3736 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3737 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3738 + subId + "' for key:" + key);
3739 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3740 }
3741 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003742 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003743 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3744 + "' for key:" + key);
3745 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003746 } finally {
3747 Binder.restoreCallingIdentity(identity);
3748 }
3749 }
3750
3751 @Override
3752 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003753 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3754 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3755 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003756 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3757 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003758 final long identity = Binder.clearCallingIdentity();
3759 try {
3760 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003761 int slotId = getSlotIndex(subId);
3762 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3763 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3764 + subId + "' for key:" + key);
3765 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3766 }
3767 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003768 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003769 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3770 + "' for key:" + key);
3771 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003772 } finally {
3773 Binder.restoreCallingIdentity(identity);
3774 }
3775 }
3776
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003777 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003778 int slotId = SubscriptionManager.getSlotIndex(subId);
3779 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003780 throw new ImsException("Invalid Subscription Id, subId=" + subId,
3781 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003782 }
3783 return slotId;
3784 }
3785
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003786 private int getSlotIndex(int subId) {
3787 int slotId = SubscriptionManager.getSlotIndex(subId);
3788 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3789 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3790 }
3791 return slotId;
3792 }
3793
Wink Saville36469e72014-06-11 15:17:00 -07003794 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07003795 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07003796 */
3797 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003798 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
3799 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07003800 final int targetSdk = getTargetSdk(callingPackage);
3801 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003802 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07003803 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07003804 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003805 mApp, subId, callingPackage, callingFeatureId,
3806 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003807 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3808 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003809
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003810 final long identity = Binder.clearCallingIdentity();
3811 try {
3812 final Phone phone = getPhone(subId);
3813 if (phone != null) {
3814 return phone.getServiceState().getDataNetworkType();
3815 } else {
3816 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3817 }
3818 } finally {
3819 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003820 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003821 }
3822
3823 /**
3824 * Returns the data network type
3825 */
3826 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003827 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
3828 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
3829 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003830 }
3831
3832 /**
3833 * Returns the data network type for a subId
3834 */
3835 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003836 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
3837 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003838 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003839 mApp, subId, callingPackage, callingFeatureId,
3840 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003841 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3842 }
3843
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003844 final long identity = Binder.clearCallingIdentity();
3845 try {
3846 final Phone phone = getPhone(subId);
3847 if (phone != null) {
3848 return phone.getServiceState().getDataNetworkType();
3849 } else {
3850 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3851 }
3852 } finally {
3853 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003854 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003855 }
3856
3857 /**
Wink Saville36469e72014-06-11 15:17:00 -07003858 * Returns the Voice network type for a subId
3859 */
3860 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003861 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
3862 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003863 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003864 mApp, subId, callingPackage, callingFeatureId,
3865 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003866 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3867 }
3868
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003869 final long identity = Binder.clearCallingIdentity();
3870 try {
3871 final Phone phone = getPhone(subId);
3872 if (phone != null) {
3873 return phone.getServiceState().getVoiceNetworkType();
3874 } else {
3875 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3876 }
3877 } finally {
3878 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003879 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003880 }
3881
3882 /**
3883 * @return true if a ICC card is present
3884 */
3885 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003886 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003887 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3888 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003889 }
3890
3891 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003892 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003893 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003894 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003895 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003896 final long identity = Binder.clearCallingIdentity();
3897 try {
3898 final Phone phone = PhoneFactory.getPhone(slotIndex);
3899 if (phone != null) {
3900 return phone.getIccCard().hasIccCard();
3901 } else {
3902 return false;
3903 }
3904 } finally {
3905 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003906 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003907 }
3908
3909 /**
3910 * Return if the current radio is LTE on CDMA. This
3911 * is a tri-state return value as for a period of time
3912 * the mode may be unknown.
3913 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003914 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003915 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003916 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003917 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003918 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003919 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
3920 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
3921 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003922 }
3923
Sanket Padawe356d7632015-06-22 14:03:32 -07003924 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003925 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
3926 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003927 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003928 mApp, subId, callingPackage, callingFeatureId,
3929 "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003930 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3931 }
3932
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003933 final long identity = Binder.clearCallingIdentity();
3934 try {
3935 final Phone phone = getPhone(subId);
3936 if (phone == null) {
3937 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3938 } else {
3939 return phone.getLteOnCdmaMode();
3940 }
3941 } finally {
3942 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003943 }
Wink Saville36469e72014-06-11 15:17:00 -07003944 }
3945
Wink Saville36469e72014-06-11 15:17:00 -07003946 /**
3947 * {@hide}
3948 * Returns Default subId, 0 in the case of single standby.
3949 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003950 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003951 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003952 }
3953
Shishir Agrawala9f32182016-04-12 12:00:16 -07003954 private int getSlotForDefaultSubscription() {
3955 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3956 }
3957
Wink Savilleb564aae2014-10-23 10:18:09 -07003958 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003959 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003960 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003961
Pengquan Menge92a50d2018-09-21 15:54:48 -07003962 private boolean isActiveSubscription(int subId) {
3963 return mSubscriptionController.isActiveSubId(subId);
3964 }
3965
Ihab Awadf2177b72013-11-25 13:33:23 -08003966 /**
3967 * @see android.telephony.TelephonyManager.WifiCallingChoices
3968 */
3969 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003970 final long identity = Binder.clearCallingIdentity();
3971 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003972 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003973 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3974 getWhenToMakeWifiCallsDefaultPreference());
3975 } finally {
3976 Binder.restoreCallingIdentity(identity);
3977 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003978 }
3979
3980 /**
3981 * @see android.telephony.TelephonyManager.WifiCallingChoices
3982 */
3983 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003984 final long identity = Binder.clearCallingIdentity();
3985 try {
3986 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003987 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003988 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3989 } finally {
3990 Binder.restoreCallingIdentity(identity);
3991 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003992 }
3993
Sailesh Nepald1e68152013-12-12 19:08:02 -08003994 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003995 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003996 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003997 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003998
Jordan Liu4c733742019-02-28 12:03:40 -08003999 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4000 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4001 if (phoneId == -1) {
4002 throw new IllegalArgumentException("Given slot index: " + slotIndex
4003 + " does not correspond to an active phone");
4004 }
4005 return PhoneFactory.getPhone(phoneId);
4006 }
4007
Shishir Agrawal566b7612013-10-28 14:41:00 -07004008 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004009 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4010 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004011 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4012 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004013 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004014 if (DBG) {
4015 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4016 }
4017 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4018 p2);
4019 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004020
Jordan Liu4c733742019-02-28 12:03:40 -08004021
4022 @Override
4023 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4024 int slotIndex, String callingPackage, String aid, int p2) {
4025 enforceModifyPermission();
4026 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4027 if (DBG) {
4028 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4029 }
4030 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4031 callingPackage, aid, p2);
4032 }
4033
4034 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4035 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004036 final long identity = Binder.clearCallingIdentity();
4037 try {
4038 if (TextUtils.equals(ISDR_AID, aid)) {
4039 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004040 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4041 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004042 if (bestComponent == null
4043 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4044 loge("The calling package is not allowed to access ISD-R.");
4045 throw new SecurityException(
4046 "The calling package is not allowed to access ISD-R.");
4047 }
Derek Tan740e1672017-06-27 14:56:27 -07004048 }
Derek Tan740e1672017-06-27 14:56:27 -07004049
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004050 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004051 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4052 null /* workSource */);
4053 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004054 return response;
4055 } finally {
4056 Binder.restoreCallingIdentity(identity);
4057 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004058 }
4059
4060 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004061 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004062 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4063 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004064 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4065 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4066 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004067
Jordan Liu4c733742019-02-28 12:03:40 -08004068 @Override
4069 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4070 enforceModifyPermission();
4071 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4072 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4073 channel);
4074 }
4075
4076 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004077 final long identity = Binder.clearCallingIdentity();
4078 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004079 if (channel < 0) {
4080 return false;
4081 }
Jordan Liu4c733742019-02-28 12:03:40 -08004082 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4083 null /* workSource */);
4084 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004085 return success;
4086 } finally {
4087 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004088 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004089 }
4090
4091 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004092 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004093 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004094 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4095 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004096 if (DBG) {
4097 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4098 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4099 + p3 + " data=" + data);
4100 }
4101 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4102 command, p1, p2, p3, data);
4103 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004104
Jordan Liu4c733742019-02-28 12:03:40 -08004105 @Override
4106 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4107 int command, int p1, int p2, int p3, String data) {
4108 enforceModifyPermission();
4109 if (DBG) {
4110 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4111 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4112 + p3 + " data=" + data);
4113 }
4114 return iccTransmitApduLogicalChannelWithPermission(
4115 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4116 data);
4117 }
4118
4119 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4120 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004121 final long identity = Binder.clearCallingIdentity();
4122 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004123 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004124 return "";
4125 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004126
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004127 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004128 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4129 null /* workSource */);
4130 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004131
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004132 // Append the returned status code to the end of the response payload.
4133 String s = Integer.toHexString(
4134 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4135 if (response.payload != null) {
4136 s = IccUtils.bytesToHexString(response.payload) + s;
4137 }
4138 return s;
4139 } finally {
4140 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004141 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004142 }
Jake Hambye994d462014-02-03 13:10:13 -08004143
Evan Charltonc66da362014-05-16 14:06:40 -07004144 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004145 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4146 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004147 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4148 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004149 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004150 if (DBG) {
4151 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4152 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4153 }
4154 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4155 cla, command, p1, p2, p3, data);
4156 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004157
Jordan Liu4c733742019-02-28 12:03:40 -08004158 @Override
4159 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4160 int command, int p1, int p2, int p3, String data) {
4161 enforceModifyPermission();
4162 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4163 if (DBG) {
4164 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4165 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4166 + " data=" + data);
4167 }
4168
4169 return iccTransmitApduBasicChannelWithPermission(
4170 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4171 p2, p3, data);
4172 }
4173
4174 // open APDU basic channel assuming the caller has sufficient permissions
4175 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4176 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004177 final long identity = Binder.clearCallingIdentity();
4178 try {
4179 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4180 && TextUtils.equals(ISDR_AID, data)) {
4181 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004182 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4183 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004184 if (bestComponent == null
4185 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4186 loge("The calling package is not allowed to select ISD-R.");
4187 throw new SecurityException(
4188 "The calling package is not allowed to select ISD-R.");
4189 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004190 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004191
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004192 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004193 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4194 null /* workSource */);
4195 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004196
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004197 // Append the returned status code to the end of the response payload.
4198 String s = Integer.toHexString(
4199 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4200 if (response.payload != null) {
4201 s = IccUtils.bytesToHexString(response.payload) + s;
4202 }
4203 return s;
4204 } finally {
4205 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004206 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004207 }
4208
4209 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004210 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004211 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004212 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4213 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004214
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004215 final long identity = Binder.clearCallingIdentity();
4216 try {
4217 if (DBG) {
4218 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4219 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4220 }
4221
4222 IccIoResult response =
4223 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4224 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4225 subId);
4226
4227 if (DBG) {
4228 log("Exchange SIM_IO [R]" + response);
4229 }
4230
4231 byte[] result = null;
4232 int length = 2;
4233 if (response.payload != null) {
4234 length = 2 + response.payload.length;
4235 result = new byte[length];
4236 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4237 } else {
4238 result = new byte[length];
4239 }
4240
4241 result[length - 1] = (byte) response.sw2;
4242 result[length - 2] = (byte) response.sw1;
4243 return result;
4244 } finally {
4245 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004246 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004247 }
4248
Nathan Haroldb3014052017-01-25 15:57:32 -08004249 /**
4250 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4251 * on a particular subscription
4252 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004253 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4254 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004255 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004256 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004257 return null;
4258 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004259
4260 final long identity = Binder.clearCallingIdentity();
4261 try {
4262 if (appType != TelephonyManager.APPTYPE_USIM
4263 && appType != TelephonyManager.APPTYPE_SIM) {
4264 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4265 return null;
4266 }
4267 Object response = sendRequest(
4268 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4269 if (response instanceof String[]) {
4270 return (String[]) response;
4271 }
yincheng zhao2737e882019-09-06 17:06:54 -07004272 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004273 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004274 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004275 } finally {
4276 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004277 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004278 }
4279
yincheng zhao2737e882019-09-06 17:06:54 -07004280 /**
4281 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4282 * subscription.
4283 *
4284 * @param subId the id of the subscription.
4285 * @param appType the uicc app type, must be USIM or SIM.
4286 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4287 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004288 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07004289 * @return number of fplmns that is successfully written to the SIM.
4290 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004291 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4292 String callingFeatureId) {
4293 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4294 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07004295 if (DBG) logv("no permissions for setForbiddenplmns");
4296 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4297 }
4298 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4299 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4300 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4301 }
4302 if (fplmns == null) {
4303 throw new IllegalArgumentException("Fplmn List provided is null");
4304 }
4305 for (String fplmn : fplmns) {
4306 if (!CellIdentity.isValidPlmn(fplmn)) {
4307 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4308 }
4309 }
4310 final long identity = Binder.clearCallingIdentity();
4311 try {
4312 Object response = sendRequest(
4313 CMD_SET_FORBIDDEN_PLMNS,
4314 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4315 subId);
4316 return (int) response;
4317 } finally {
4318 Binder.restoreCallingIdentity(identity);
4319 }
4320 }
4321
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004322 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004323 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004324 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4325 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004326
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004327 final long identity = Binder.clearCallingIdentity();
4328 try {
4329 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4330 if (response.payload == null) {
4331 return "";
4332 }
Evan Charltonc66da362014-05-16 14:06:40 -07004333
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004334 // Append the returned status code to the end of the response payload.
4335 String s = Integer.toHexString(
4336 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4337 s = IccUtils.bytesToHexString(response.payload) + s;
4338 return s;
4339 } finally {
4340 Binder.restoreCallingIdentity(identity);
4341 }
Evan Charltonc66da362014-05-16 14:06:40 -07004342 }
4343
Jake Hambye994d462014-02-03 13:10:13 -08004344 /**
4345 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4346 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4347 *
4348 * @param itemID the ID of the item to read
4349 * @return the NV item as a String, or null on error.
4350 */
4351 @Override
4352 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004353 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004354 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4355 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004356
4357 final long identity = Binder.clearCallingIdentity();
4358 try {
4359 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004360 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004361 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4362 return value;
4363 } finally {
4364 Binder.restoreCallingIdentity(identity);
4365 }
Jake Hambye994d462014-02-03 13:10:13 -08004366 }
4367
4368 /**
4369 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4370 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4371 *
4372 * @param itemID the ID of the item to read
4373 * @param itemValue the value to write, as a String
4374 * @return true on success; false on any failure
4375 */
4376 @Override
4377 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004378 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004379 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4380 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004381
4382 final long identity = Binder.clearCallingIdentity();
4383 try {
4384 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4385 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004386 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004387 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4388 return success;
4389 } finally {
4390 Binder.restoreCallingIdentity(identity);
4391 }
Jake Hambye994d462014-02-03 13:10:13 -08004392 }
4393
4394 /**
4395 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4396 * Used for device configuration by some CDMA operators.
4397 *
4398 * @param preferredRoamingList byte array containing the new PRL
4399 * @return true on success; false on any failure
4400 */
4401 @Override
4402 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004403 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4404 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004405
4406 final long identity = Binder.clearCallingIdentity();
4407 try {
4408 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4409 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4410 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4411 return success;
4412 } finally {
4413 Binder.restoreCallingIdentity(identity);
4414 }
Jake Hambye994d462014-02-03 13:10:13 -08004415 }
4416
4417 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004418 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004419 * Used for device configuration by some CDMA operators.
4420 *
chen xu6dac5ab2018-10-26 17:39:23 -07004421 * @param slotIndex - device slot.
4422 *
Jake Hambye994d462014-02-03 13:10:13 -08004423 * @return true on success; false on any failure
4424 */
4425 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004426 public boolean resetModemConfig(int slotIndex) {
4427 Phone phone = PhoneFactory.getPhone(slotIndex);
4428 if (phone != null) {
4429 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4430 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004431
chen xu6dac5ab2018-10-26 17:39:23 -07004432 final long identity = Binder.clearCallingIdentity();
4433 try {
4434 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4435 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4436 return success;
4437 } finally {
4438 Binder.restoreCallingIdentity(identity);
4439 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004440 }
chen xu6dac5ab2018-10-26 17:39:23 -07004441 return false;
4442 }
4443
4444 /**
4445 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4446 *
4447 * @param slotIndex - device slot.
4448 *
4449 * @return true on success; false on any failure
4450 */
4451 @Override
4452 public boolean rebootModem(int slotIndex) {
4453 Phone phone = PhoneFactory.getPhone(slotIndex);
4454 if (phone != null) {
4455 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4456 mApp, phone.getSubId(), "rebootModem");
4457
4458 final long identity = Binder.clearCallingIdentity();
4459 try {
4460 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4461 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4462 return success;
4463 } finally {
4464 Binder.restoreCallingIdentity(identity);
4465 }
4466 }
4467 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004468 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004469
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004470 public String[] getPcscfAddress(String apnType, String callingPackage,
4471 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004472 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004473 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4474 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004475 return new String[0];
4476 }
4477
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004478 final long identity = Binder.clearCallingIdentity();
4479 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004480 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004481 } finally {
4482 Binder.restoreCallingIdentity(identity);
4483 }
Wink Saville36469e72014-06-11 15:17:00 -07004484 }
4485
Brad Ebinger51f743a2017-01-23 13:50:20 -08004486 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004487 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4488 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004489 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004490 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004491 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004492
4493 final long identity = Binder.clearCallingIdentity();
4494 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004495 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004496 // may happen if the device does not support IMS.
4497 return;
4498 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004499 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004500 } finally {
4501 Binder.restoreCallingIdentity(identity);
4502 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004503 }
4504
4505 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004506 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4507 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004508 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004509 public void disableIms(int slotId) {
4510 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004511
4512 final long identity = Binder.clearCallingIdentity();
4513 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004514 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004515 // may happen if the device does not support IMS.
4516 return;
4517 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004518 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004519 } finally {
4520 Binder.restoreCallingIdentity(identity);
4521 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004522 }
4523
4524 /**
4525 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4526 * feature or {@link null} if the service is not available. If the feature is available, the
4527 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4528 */
4529 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004530 IImsServiceFeatureCallback callback) {
4531 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004532
4533 final long identity = Binder.clearCallingIdentity();
4534 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004535 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004536 // may happen if the device does not support IMS.
4537 return null;
4538 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004539 return mImsResolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004540 } finally {
4541 Binder.restoreCallingIdentity(identity);
4542 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004543 }
4544
4545 /**
4546 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4547 * feature during emergency calling or {@link null} if the service is not available. If the
4548 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4549 * listener for feature updates.
4550 */
4551 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4552 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004553
4554 final long identity = Binder.clearCallingIdentity();
4555 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004556 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004557 // may happen if the device does not support IMS.
4558 return null;
4559 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004560 return mImsResolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004561 } finally {
4562 Binder.restoreCallingIdentity(identity);
4563 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004564 }
4565
Brad Ebinger5f64b052017-12-14 14:26:15 -08004566 /**
4567 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004568 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004569 */
4570 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4571 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004572
4573 final long identity = Binder.clearCallingIdentity();
4574 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004575 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004576 // may happen if the device does not support IMS.
4577 return null;
4578 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004579 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004580 } finally {
4581 Binder.restoreCallingIdentity(identity);
4582 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004583 }
4584
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004585 /**
4586 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004587 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004588 */
4589 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4590 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004591
4592 final long identity = Binder.clearCallingIdentity();
4593 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004594 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004595 // may happen if the device does not support IMS.
4596 return null;
4597 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004598 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004599 } finally {
4600 Binder.restoreCallingIdentity(identity);
4601 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004602 }
4603
Brad Ebinger884c07b2018-02-15 16:17:40 -08004604 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004605 * Sets the ImsService Package Name that Telephony will bind to.
4606 *
Brad Ebinger24c29992019-12-05 13:03:21 -08004607 * @param slotIndex the slot ID that the ImsService should bind for.
4608 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07004609 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08004610 * @param featureTypes An integer array of feature types associated with a packageName.
4611 * @param packageName The name of the package that the current configuration will be replaced
4612 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004613 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004614 */
Brad Ebinger24c29992019-12-05 13:03:21 -08004615 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
4616 int[] featureTypes, String packageName) {
4617 int[] subIds = SubscriptionManager.getSubId(slotIndex);
4618 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07004619 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4620 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08004621 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07004622
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004623 final long identity = Binder.clearCallingIdentity();
4624 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004625 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004626 // may happen if the device does not support IMS.
4627 return false;
4628 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004629 Map<Integer, String> featureConfig = new HashMap<>();
4630 for (int featureType : featureTypes) {
4631 featureConfig.put(featureType, packageName);
4632 }
4633 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
4634 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004635 } finally {
4636 Binder.restoreCallingIdentity(identity);
4637 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004638 }
4639
4640 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08004641 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004642 *
4643 * @param slotId The slot that the ImsService is associated with.
4644 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4645 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08004646 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004647 * @return the package name of the ImsService configuration.
4648 */
Brad Ebinger24c29992019-12-05 13:03:21 -08004649 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
4650 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004651 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08004652 TelephonyPermissions
4653 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4654 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4655 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07004656
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004657 final long identity = Binder.clearCallingIdentity();
4658 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004659 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004660 // may happen if the device does not support IMS.
4661 return "";
4662 }
Brad Ebingera80c3312019-12-02 10:59:39 -08004663 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08004664 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
4665 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004666 } finally {
4667 Binder.restoreCallingIdentity(identity);
4668 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004669 }
4670
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004671 /**
4672 * Get the MmTelFeature state associated with the requested subscription id.
4673 * @param subId The subscription that the MmTelFeature is associated with.
4674 * @param callback A callback with an integer containing the
4675 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
4676 */
4677 @Override
4678 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
4679 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
4680 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4681 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4682 "IMS not available on device.");
4683 }
4684 final long token = Binder.clearCallingIdentity();
4685 try {
4686 int slotId = getSlotIndex(subId);
4687 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4688 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
4689 + subId + "'");
4690 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4691 }
4692 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
4693 try {
4694 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
4695 } catch (RemoteException e) {
4696 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
4697 + "Ignore");
4698 }
4699 });
4700 } finally {
4701 Binder.restoreCallingIdentity(token);
4702 }
4703 }
4704
Wink Saville36469e72014-06-11 15:17:00 -07004705 public void setImsRegistrationState(boolean registered) {
4706 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004707
4708 final long identity = Binder.clearCallingIdentity();
4709 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004710 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004711 } finally {
4712 Binder.restoreCallingIdentity(identity);
4713 }
Wink Saville36469e72014-06-11 15:17:00 -07004714 }
4715
4716 /**
Stuart Scott54788802015-03-30 13:18:01 -07004717 * Set the network selection mode to automatic.
4718 *
4719 */
4720 @Override
4721 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004722 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4723 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004724
Pengquan Menge92a50d2018-09-21 15:54:48 -07004725 if (!isActiveSubscription(subId)) {
4726 return;
4727 }
4728
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004729 final long identity = Binder.clearCallingIdentity();
4730 try {
4731 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4732 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4733 } finally {
4734 Binder.restoreCallingIdentity(identity);
4735 }
Stuart Scott54788802015-03-30 13:18:01 -07004736 }
4737
Pengquan Mengea84e042018-09-20 14:57:26 -07004738 /**
4739 * Ask the radio to connect to the input network and change selection mode to manual.
4740 *
4741 * @param subId the id of the subscription.
4742 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4743 * the operator to attach to.
4744 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4745 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4746 * normal network selection next time.
4747 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004748 */
4749 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004750 public boolean setNetworkSelectionModeManual(
4751 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004752 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4753 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004754
4755 if (!isActiveSubscription(subId)) {
4756 return false;
4757 }
4758
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004759 final long identity = Binder.clearCallingIdentity();
4760 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004761 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004762 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004763 if (DBG) {
4764 log("setNetworkSelectionModeManual: subId: " + subId
4765 + " operator: " + operatorInfo);
4766 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004767 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4768 } finally {
4769 Binder.restoreCallingIdentity(identity);
4770 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004771 }
4772
4773 /**
4774 * Scans for available networks.
4775 */
4776 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004777 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
4778 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004779 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4780 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004781 LocationAccessPolicy.LocationPermissionResult locationResult =
4782 LocationAccessPolicy.checkLocationPermission(mApp,
4783 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4784 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004785 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08004786 .setCallingPid(Binder.getCallingPid())
4787 .setCallingUid(Binder.getCallingUid())
4788 .setMethod("getCellNetworkScanResults")
4789 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4790 .build());
4791 switch (locationResult) {
4792 case DENIED_HARD:
4793 throw new SecurityException("Not allowed to access scan results -- location");
4794 case DENIED_SOFT:
4795 return null;
4796 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004797
Pengquan Menga1bb6272018-09-06 09:59:22 -07004798 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004799 try {
4800 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004801 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004802 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004803 } finally {
4804 Binder.restoreCallingIdentity(identity);
4805 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004806 }
4807
4808 /**
yinxub1bed742017-04-17 11:45:04 -07004809 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004810 *
yinxub1bed742017-04-17 11:45:04 -07004811 * @param subId id of the subscription
4812 * @param request contains the radio access networks with bands/channels to scan
4813 * @param messenger callback messenger for scan results or errors
4814 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004815 * @return the id of the requested scan which can be used to stop the scan.
4816 */
4817 @Override
4818 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004819 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004820 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4821 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004822 LocationAccessPolicy.LocationPermissionResult locationResult =
4823 LocationAccessPolicy.checkLocationPermission(mApp,
4824 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4825 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004826 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08004827 .setCallingPid(Binder.getCallingPid())
4828 .setCallingUid(Binder.getCallingUid())
4829 .setMethod("requestNetworkScan")
4830 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4831 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004832 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07004833 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08004834 if (e != null) {
4835 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4836 throw e;
4837 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07004838 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004839 return TelephonyScanManager.INVALID_SCAN_ID;
4840 }
4841 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004842 }
Hall Liu912dfd32019-04-25 14:02:26 -07004843 int callingUid = Binder.getCallingUid();
4844 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07004845 final long identity = Binder.clearCallingIdentity();
4846 try {
4847 return mNetworkScanRequestTracker.startNetworkScan(
4848 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07004849 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07004850 } finally {
4851 Binder.restoreCallingIdentity(identity);
4852 }
yinxu504e1392017-04-12 16:03:22 -07004853 }
4854
Hall Liub2ac8ef2019-02-28 15:56:23 -08004855 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07004856 NetworkScanRequest request, int subId) {
4857 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
4858 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
4859 boolean hasNetworkScanPermission =
4860 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4861 == PERMISSION_GRANTED;
4862
4863 if (!hasCarrierPriv && !hasNetworkScanPermission) {
4864 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
4865 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08004866 }
4867
4868 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4869 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004870 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4871 return new SecurityException("Specific channels must not be"
4872 + " scanned without location access.");
4873 }
4874 }
4875 }
4876
Hall Liub2ac8ef2019-02-28 15:56:23 -08004877 return null;
4878 }
4879
yinxu504e1392017-04-12 16:03:22 -07004880 /**
4881 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004882 *
4883 * @param subId id of the subscription
4884 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004885 */
4886 @Override
4887 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004888 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4889 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004890
Hall Liu912dfd32019-04-25 14:02:26 -07004891 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004892 final long identity = Binder.clearCallingIdentity();
4893 try {
Hall Liu912dfd32019-04-25 14:02:26 -07004894 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004895 } finally {
4896 Binder.restoreCallingIdentity(identity);
4897 }
yinxu504e1392017-04-12 16:03:22 -07004898 }
4899
4900 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004901 * Get the calculated preferred network type.
4902 * Used for debugging incorrect network type.
4903 *
4904 * @return the preferred network type, defined in RILConstants.java.
4905 */
4906 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004907 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004908 final Phone defaultPhone = getDefaultPhone();
4909 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004910 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004911 return RILConstants.PREFERRED_NETWORK_MODE;
4912 }
4913
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004914 final long identity = Binder.clearCallingIdentity();
4915 try {
4916 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004917 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004918 } finally {
4919 Binder.restoreCallingIdentity(identity);
4920 }
Junda Liu84d15a22014-07-02 11:21:04 -07004921 }
4922
4923 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004924 * Get the preferred network type.
4925 * Used for device configuration by some CDMA operators.
4926 *
4927 * @return the preferred network type, defined in RILConstants.java.
4928 */
4929 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004930 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08004931 TelephonyPermissions
4932 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4933 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004934
4935 final long identity = Binder.clearCallingIdentity();
4936 try {
4937 if (DBG) log("getPreferredNetworkType");
4938 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4939 int networkType = (result != null ? result[0] : -1);
4940 if (DBG) log("getPreferredNetworkType: " + networkType);
4941 return networkType;
4942 } finally {
4943 Binder.restoreCallingIdentity(identity);
4944 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004945 }
4946
4947 /**
4948 * Set the preferred network type.
4949 * Used for device configuration by some CDMA operators.
4950 *
4951 * @param networkType the preferred network type, defined in RILConstants.java.
4952 * @return true on success; false on any failure.
4953 */
4954 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004955 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004956 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4957 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004958
4959 final long identity = Binder.clearCallingIdentity();
4960 try {
4961 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4962 Boolean success = (Boolean) sendRequest(
4963 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4964 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4965 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004966 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004967 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4968 }
4969 return success;
4970 } finally {
4971 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004972 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004973 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004974
4975 /**
Miaoa84611c2019-03-15 09:21:10 +08004976 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004977 *
Miaoa84611c2019-03-15 09:21:10 +08004978 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004979 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004980 * @hide
4981 */
4982 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08004983 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004984 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004985 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08004986 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004987 try {
Miaoa84611c2019-03-15 09:21:10 +08004988 if (phone != null) {
4989 return phone.hasMatchedTetherApnSetting();
4990 } else {
4991 return false;
4992 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004993 } finally {
4994 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004995 }
Junda Liu475951f2014-11-07 16:45:03 -08004996 }
4997
4998 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004999 * Set mobile data enabled
5000 * Used by the user through settings etc to turn on/off mobile data
5001 *
5002 * @param enable {@code true} turn turn data on, else {@code false}
5003 */
5004 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005005 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005006 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5007 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005008
5009 final long identity = Binder.clearCallingIdentity();
5010 try {
5011 int phoneId = mSubscriptionController.getPhoneId(subId);
5012 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5013 Phone phone = PhoneFactory.getPhone(phoneId);
5014 if (phone != null) {
5015 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08005016 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005017 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005018 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005019 }
5020 } finally {
5021 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005022 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005023 }
5024
5025 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005026 * Get the user enabled state of Mobile Data.
5027 *
5028 * TODO: remove and use isUserDataEnabled.
5029 * This can't be removed now because some vendor codes
5030 * calls through ITelephony directly while they should
5031 * use TelephonyManager.
5032 *
5033 * @return true on enabled
5034 */
5035 @Override
5036 public boolean getDataEnabled(int subId) {
5037 return isUserDataEnabled(subId);
5038 }
5039
5040 /**
5041 * Get whether mobile data is enabled per user setting.
5042 *
5043 * There are other factors deciding whether mobile data is actually enabled, but they are
5044 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005045 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005046 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005047 *
5048 * @return {@code true} if data is enabled else {@code false}
5049 */
5050 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005051 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005052 try {
5053 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5054 null);
5055 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005056 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5057 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005058 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005059
5060 final long identity = Binder.clearCallingIdentity();
5061 try {
5062 int phoneId = mSubscriptionController.getPhoneId(subId);
5063 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5064 Phone phone = PhoneFactory.getPhone(phoneId);
5065 if (phone != null) {
5066 boolean retVal = phone.isUserDataEnabled();
5067 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5068 return retVal;
5069 } else {
5070 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5071 return false;
5072 }
5073 } finally {
5074 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005075 }
5076 }
5077
5078 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08005079 * Checks if the device is capable of mobile data by considering whether whether the
5080 * user has enabled mobile data, whether the carrier has enabled mobile data, and
5081 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08005082 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08005083 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08005084 */
5085 @Override
5086 public boolean isDataEnabled(int subId) {
Shuo Qian8ee4e882020-01-08 14:30:06 -08005087 enforceReadPrivilegedPermission("isDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005088
5089 final long identity = Binder.clearCallingIdentity();
5090 try {
5091 int phoneId = mSubscriptionController.getPhoneId(subId);
5092 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5093 Phone phone = PhoneFactory.getPhone(phoneId);
5094 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005095 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005096 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5097 return retVal;
5098 } else {
5099 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5100 return false;
5101 }
5102 } finally {
5103 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005104 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005105 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005106
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005107 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
5108 Phone phone) {
5109 //load access rules from carrier configs, and check those as well: b/139133814
5110 SubscriptionController subController = SubscriptionController.getInstance();
5111 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5112 || subController == null) return privilegeFromSim;
5113
5114 int uid = Binder.getCallingUid();
5115 PackageManager pkgMgr = phone.getContext().getPackageManager();
5116 String[] packages = pkgMgr.getPackagesForUid(uid);
5117
5118 final long identity = Binder.clearCallingIdentity();
5119 try {
5120 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5121 SubscriptionManager subManager = (SubscriptionManager)
5122 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5123 for (String pkg : packages) {
5124 if (subManager.canManageSubscription(subInfo, pkg)) {
5125 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5126 }
5127 }
5128 return privilegeFromSim;
5129 } finally {
5130 Binder.restoreCallingIdentity(identity);
5131 }
5132 }
5133
5134 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5135 String pkgName) {
5136 //load access rules from carrier configs, and check those as well: b/139133814
5137 SubscriptionController subController = SubscriptionController.getInstance();
5138 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5139 || subController == null) return privilegeFromSim;
5140
5141 final long identity = Binder.clearCallingIdentity();
5142 try {
5143 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5144 SubscriptionManager subManager = (SubscriptionManager)
5145 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5146 return subManager.canManageSubscription(subInfo, pkgName)
5147 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5148 } finally {
5149 Binder.restoreCallingIdentity(identity);
5150 }
5151 }
5152
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005153 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005154 public int getCarrierPrivilegeStatus(int subId) {
5155 final Phone phone = getPhone(subId);
5156 if (phone == null) {
5157 loge("getCarrierPrivilegeStatus: Invalid subId");
5158 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5159 }
5160 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005161 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005162 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005163 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5164 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005165
5166 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5167 card.getCarrierPrivilegeStatusForCurrentTransaction(
5168 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005169 }
Junda Liu29340342014-07-10 15:23:27 -07005170
5171 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005172 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005173 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005174 final Phone phone = getPhone(subId);
5175 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005176 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005177 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5178 }
5179 UiccProfile profile =
5180 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5181 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005182 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005183 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5184 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005185 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08005186 profile.getCarrierPrivilegeStatusForUid(
5187 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005188 }
5189
5190 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005191 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5192 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005193 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005194 }
5195
5196 int phoneId = SubscriptionManager.getPhoneId(subId);
5197 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005198 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005199 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005200 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5201 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005202 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5203 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5204 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005205 }
5206
5207 @Override
5208 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005209 if (TextUtils.isEmpty(pkgName))
5210 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005211 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5212 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5213 UiccCard card = UiccController.getInstance().getUiccCard(i);
5214 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005215 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005216 continue;
5217 }
5218
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005219 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5220 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5221 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005222 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5223 break;
5224 }
5225 }
5226
5227 return result;
Junda Liu29340342014-07-10 15:23:27 -07005228 }
Derek Tan89e89d42014-07-08 17:00:10 -07005229
5230 @Override
Junda Liue64de782015-04-16 17:19:16 -07005231 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5232 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5233 loge("phoneId " + phoneId + " is not valid.");
5234 return null;
5235 }
5236 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005237 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005238 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005239 return null ;
5240 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005241 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005242 }
5243
Amith Yamasani6e118872016-02-19 12:53:51 -08005244 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005245 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005246 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005247 List<String> privilegedPackages = new ArrayList<>();
5248 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005249 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5250 // has UICC in that slot.
5251 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005252 if (card.hasCarrierPrivilegeRules()) {
5253 if (packages == null) {
5254 // Only check packages in user 0 for now
5255 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005256 PackageManager.MATCH_DISABLED_COMPONENTS
5257 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005258 | PackageManager.GET_SIGNING_CERTIFICATES,
5259 UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08005260 }
5261 for (int p = packages.size() - 1; p >= 0; p--) {
5262 PackageInfo pkgInfo = packages.get(p);
5263 if (pkgInfo != null && pkgInfo.packageName != null
5264 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005265 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005266 privilegedPackages.add(pkgInfo.packageName);
5267 }
5268 }
5269 }
5270 }
5271 return privilegedPackages;
5272 }
5273
chen xuf7e9fe82019-05-09 19:31:02 -07005274 @Override
5275 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00005276 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5277
5278 final long identity = Binder.clearCallingIdentity();
5279
chen xuf7e9fe82019-05-09 19:31:02 -07005280 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00005281 try {
5282 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5283 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5284 }
5285 } finally {
5286 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07005287 }
5288 return privilegedPackages;
5289 }
5290
Wink Savilleb564aae2014-10-23 10:18:09 -07005291 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005292 final Phone phone = getPhone(subId);
5293 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005294 if (card == null) {
5295 loge("getIccId: No UICC");
5296 return null;
5297 }
5298 String iccId = card.getIccId();
5299 if (TextUtils.isEmpty(iccId)) {
5300 loge("getIccId: ICC ID is null or empty.");
5301 return null;
5302 }
5303 return iccId;
5304 }
5305
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005306 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005307 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5308 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005309 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005310 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005311
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005312 final long identity = Binder.clearCallingIdentity();
5313 try {
5314 final String iccId = getIccId(subId);
5315 final Phone phone = getPhone(subId);
5316 if (phone == null) {
5317 return false;
5318 }
5319 final String subscriberId = phone.getSubscriberId();
5320
5321 if (DBG_MERGE) {
5322 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
5323 + subscriberId + " to " + number);
5324 }
5325
5326 if (TextUtils.isEmpty(iccId)) {
5327 return false;
5328 }
5329
5330 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5331
5332 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5333 if (alphaTag == null) {
5334 editor.remove(alphaTagPrefKey);
5335 } else {
5336 editor.putString(alphaTagPrefKey, alphaTag);
5337 }
5338
5339 // Record both the line number and IMSI for this ICCID, since we need to
5340 // track all merged IMSIs based on line number
5341 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5342 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5343 if (number == null) {
5344 editor.remove(numberPrefKey);
5345 editor.remove(subscriberPrefKey);
5346 } else {
5347 editor.putString(numberPrefKey, number);
5348 editor.putString(subscriberPrefKey, subscriberId);
5349 }
5350
5351 editor.commit();
5352 return true;
5353 } finally {
5354 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005355 }
Derek Tan7226c842014-07-02 17:42:23 -07005356 }
5357
5358 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005359 public String getLine1NumberForDisplay(int subId, String callingPackage,
5360 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07005361 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005362 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005363 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005364 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005365 return null;
5366 }
Derek Tan97ebb422014-09-05 16:55:38 -07005367
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005368 final long identity = Binder.clearCallingIdentity();
5369 try {
5370 String iccId = getIccId(subId);
5371 if (iccId != null) {
5372 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5373 if (DBG_MERGE) {
5374 log("getLine1NumberForDisplay returning "
5375 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5376 }
5377 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005378 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005379 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5380 return null;
5381 } finally {
5382 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005383 }
Derek Tan7226c842014-07-02 17:42:23 -07005384 }
5385
5386 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005387 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
5388 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005389 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005390 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005391 return null;
5392 }
Derek Tan97ebb422014-09-05 16:55:38 -07005393
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005394 final long identity = Binder.clearCallingIdentity();
5395 try {
5396 String iccId = getIccId(subId);
5397 if (iccId != null) {
5398 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5399 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5400 }
5401 return null;
5402 } finally {
5403 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005404 }
Derek Tan7226c842014-07-02 17:42:23 -07005405 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005406
5407 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005408 public String[] getMergedSubscriberIds(int subId, String callingPackage,
5409 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005410 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5411 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005412 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005413 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005414 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005415 return null;
5416 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005417
Jordan Liub49b04b2019-05-06 14:45:15 -07005418 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5419 // the process, where TelephonyManager was instantiated.
5420 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005421 final long identity = Binder.clearCallingIdentity();
5422 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005423 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005424 final TelephonyManager tele = TelephonyManager.from(context);
5425 final SubscriptionManager sub = SubscriptionManager.from(context);
5426
5427 // Figure out what subscribers are currently active
5428 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005429
Jordan Liub49b04b2019-05-06 14:45:15 -07005430 // Only consider subs which match the current subId
5431 // This logic can be simplified. See b/131189269 for progress.
5432 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005433 activeSubscriberIds.add(tele.getSubscriberId(subId));
5434 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005435
5436 // First pass, find a number override for an active subscriber
5437 String mergeNumber = null;
5438 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5439 for (String key : prefs.keySet()) {
5440 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5441 final String subscriberId = (String) prefs.get(key);
5442 if (activeSubscriberIds.contains(subscriberId)) {
5443 final String iccId = key.substring(
5444 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5445 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5446 mergeNumber = (String) prefs.get(numberKey);
5447 if (DBG_MERGE) {
5448 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5449 + " for active subscriber " + subscriberId);
5450 }
5451 if (!TextUtils.isEmpty(mergeNumber)) {
5452 break;
5453 }
5454 }
5455 }
5456 }
5457
5458 // Shortcut when no active merged subscribers
5459 if (TextUtils.isEmpty(mergeNumber)) {
5460 return null;
5461 }
5462
5463 // Second pass, find all subscribers under that line override
5464 final ArraySet<String> result = new ArraySet<>();
5465 for (String key : prefs.keySet()) {
5466 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5467 final String number = (String) prefs.get(key);
5468 if (mergeNumber.equals(number)) {
5469 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5470 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5471 final String subscriberId = (String) prefs.get(subscriberKey);
5472 if (!TextUtils.isEmpty(subscriberId)) {
5473 result.add(subscriberId);
5474 }
5475 }
5476 }
5477 }
5478
5479 final String[] resultArray = result.toArray(new String[result.size()]);
5480 Arrays.sort(resultArray);
5481 if (DBG_MERGE) {
5482 Slog.d(LOG_TAG,
5483 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5484 }
5485 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005486 } finally {
5487 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005488 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005489 }
5490
5491 @Override
zoey chen38003472019-12-13 17:16:31 +08005492 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
5493 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07005494
5495 final long identity = Binder.clearCallingIdentity();
5496 try {
5497 final TelephonyManager telephonyManager = mApp.getSystemService(
5498 TelephonyManager.class);
5499 String subscriberId = telephonyManager.getSubscriberId(subId);
5500 if (subscriberId == null) {
5501 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08005502 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07005503 + subId);
5504 }
5505 return null;
5506 }
5507
5508 final SubscriptionInfo info = SubscriptionController.getInstance()
5509 .getSubscriptionInfo(subId);
5510 final ParcelUuid groupUuid = info.getGroupUuid();
5511 // If it doesn't belong to any group, return just subscriberId of itself.
5512 if (groupUuid == null) {
5513 return new String[]{subscriberId};
5514 }
5515
5516 // Get all subscriberIds from the group.
5517 final List<String> mergedSubscriberIds = new ArrayList<>();
5518 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005519 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
5520 mApp.getFeatureId());
Malcolm Chen6ca97372019-07-01 16:28:21 -07005521 for (SubscriptionInfo subInfo : groupInfos) {
5522 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
5523 if (subscriberId != null) {
5524 mergedSubscriberIds.add(subscriberId);
5525 }
5526 }
5527
5528 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
5529 } finally {
5530 Binder.restoreCallingIdentity(identity);
5531
5532 }
5533 }
5534
5535 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005536 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005537 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005538 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005539
5540 final long identity = Binder.clearCallingIdentity();
5541 try {
5542 final Phone phone = getPhone(subId);
5543 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5544 } finally {
5545 Binder.restoreCallingIdentity(identity);
5546 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005547 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005548
5549 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005550 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005551 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5552 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005553 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5554 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005555
5556 final long identity = Binder.clearCallingIdentity();
5557 try {
5558 final Phone phone = getPhone(subId);
5559 if (phone == null) {
5560 return false;
5561 }
5562 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5563 cdmaNonRoamingList);
5564 } finally {
5565 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005566 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005567 }
5568
5569 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005570 @Deprecated
5571 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5572 enforceModifyPermission();
5573
5574 int returnValue = 0;
5575 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005576 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005577 if(result.exception == null) {
5578 if (result.result != null) {
5579 byte[] responseData = (byte[])(result.result);
5580 if(responseData.length > oemResp.length) {
5581 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5582 responseData.length + "bytes. Buffer Size is " +
5583 oemResp.length + "bytes.");
5584 }
5585 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5586 returnValue = responseData.length;
5587 }
5588 } else {
5589 CommandException ex = (CommandException) result.exception;
5590 returnValue = ex.getCommandError().ordinal();
5591 if(returnValue > 0) returnValue *= -1;
5592 }
5593 } catch (RuntimeException e) {
5594 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5595 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5596 if(returnValue > 0) returnValue *= -1;
5597 }
5598
5599 return returnValue;
5600 }
5601
5602 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005603 public void setRadioCapability(RadioAccessFamily[] rafs) {
5604 try {
5605 ProxyController.getInstance().setRadioCapability(rafs);
5606 } catch (RuntimeException e) {
5607 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5608 }
5609 }
5610
5611 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005612 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005613 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005614 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005615 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005616 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005617 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005618 final long identity = Binder.clearCallingIdentity();
5619 try {
chen xub97461a2018-10-26 14:17:57 -07005620 TelephonyPermissions
5621 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5622 mApp, phone.getSubId(), "getRadioAccessFamily");
5623 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005624 } finally {
5625 Binder.restoreCallingIdentity(identity);
5626 }
chen xub97461a2018-10-26 14:17:57 -07005627 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005628 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005629
5630 @Override
5631 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005632 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005633 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005634
5635 final long identity = Binder.clearCallingIdentity();
5636 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005637 ImsManager.getInstance(defaultPhone.getContext(),
5638 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005639 } finally {
5640 Binder.restoreCallingIdentity(identity);
5641 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005642 }
5643
5644 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005645 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005646 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005647 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5648 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005649 return false;
5650 }
Svet Ganovb320e182015-04-16 12:30:10 -07005651
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005652 final long identity = Binder.clearCallingIdentity();
5653 try {
5654 // Check the user preference and the system-level IMS setting. Even if the user has
5655 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5656 // In the long run, we may instead need to check if there exists a connection service
5657 // which can support video calling.
5658 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005659 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005660 return imsManager.isVtEnabledByPlatform()
5661 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5662 && imsManager.isVtEnabledByUser();
5663 } finally {
5664 Binder.restoreCallingIdentity(identity);
5665 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005666 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005667
Andrew Leea1239f22015-03-02 17:44:07 -08005668 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005669 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
5670 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005671 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005672 mApp, subId, callingPackage, callingFeatureId,
5673 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005674 return false;
5675 }
5676
5677 final long identity = Binder.clearCallingIdentity();
5678 try {
5679 CarrierConfigManager configManager =
5680 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005681 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005682 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5683 } finally {
5684 Binder.restoreCallingIdentity(identity);
5685 }
Andrew Leea1239f22015-03-02 17:44:07 -08005686 }
5687
5688 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005689 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005690 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005691 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005692 return false;
5693 }
5694
5695 final long identity = Binder.clearCallingIdentity();
5696 try {
5697 CarrierConfigManager configManager =
5698 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005699 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005700 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5701 } finally {
5702 Binder.restoreCallingIdentity(identity);
5703 }
Andrew Leea1239f22015-03-02 17:44:07 -08005704 }
5705
Andrew Lee9431b832015-03-09 18:46:45 -07005706 @Override
5707 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07005708 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005709 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005710 }
5711
5712 @Override
5713 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005714 final long identity = Binder.clearCallingIdentity();
5715 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005716 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005717 } finally {
5718 Binder.restoreCallingIdentity(identity);
5719 }
Andrew Lee9431b832015-03-09 18:46:45 -07005720 }
5721
Hall Liuf6668912018-10-31 17:05:23 -07005722 /**
5723 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5724 * support for the feature and device firmware support.
5725 *
5726 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5727 */
5728 @Override
5729 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005730 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005731 final Phone phone = getPhone(subscriptionId);
5732 if (phone == null) {
5733 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5734 return false;
5735 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005736 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005737 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005738 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5739 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005740 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005741 return isCarrierSupported && isDeviceSupported;
5742 } finally {
5743 Binder.restoreCallingIdentity(identity);
5744 }
Hall Liu98187582018-01-22 19:15:32 -08005745 }
5746
Hall Liuf6668912018-10-31 17:05:23 -07005747 /**
Hall Liuf2daa022019-07-23 18:39:00 -07005748 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
5749 * RTT setting, will return true if the device and carrier both support RTT.
5750 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07005751 */
5752 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005753 final long identity = Binder.clearCallingIdentity();
5754 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00005755 boolean isRttSupported = isRttSupported(subscriptionId);
5756 boolean isUserRttSettingOn = Settings.Secure.getInt(
5757 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
5758 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
5759 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
5760 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005761 } finally {
5762 Binder.restoreCallingIdentity(identity);
5763 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005764 }
5765
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005766 @Deprecated
5767 @Override
5768 public String getDeviceId(String callingPackage) {
5769 return getDeviceIdWithFeature(callingPackage, null);
5770 }
5771
Sanket Padawe7310cc72015-01-14 09:53:20 -08005772 /**
5773 * Returns the unique device ID of phone, for example, the IMEI for
5774 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5775 *
5776 * <p>Requires Permission:
5777 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5778 */
5779 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005780 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005781 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005782 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005783 return null;
5784 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005785 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005786 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005787 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005788 return null;
5789 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005790
5791 final long identity = Binder.clearCallingIdentity();
5792 try {
5793 return phone.getDeviceId();
5794 } finally {
5795 Binder.restoreCallingIdentity(identity);
5796 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005797 }
5798
Ping Sunc67b7c22016-03-02 19:16:45 +08005799 /**
5800 * {@hide}
5801 * Returns the IMS Registration Status on a particular subid
5802 *
5803 * @param subId
5804 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005805 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005806 Phone phone = getPhone(subId);
5807 if (phone != null) {
5808 return phone.isImsRegistered();
5809 } else {
5810 return false;
5811 }
5812 }
5813
Santos Cordon7a1885b2015-02-03 11:15:19 -08005814 @Override
5815 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005816 final long identity = Binder.clearCallingIdentity();
5817 try {
5818 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5819 } finally {
5820 Binder.restoreCallingIdentity(identity);
5821 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005822 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005823
Tyler Gunnf70ed162019-04-03 15:28:53 -07005824 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07005825 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005826 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07005827 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005828 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07005829 throw new SecurityException("Requires READ_PHONE_STATE permission.");
5830 }
5831 final long identity = Binder.clearCallingIdentity();
5832 try {
5833 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
5834 } finally {
5835 Binder.restoreCallingIdentity(identity);
5836 }
5837 }
5838
5839 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07005840 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5841 final long identity = Binder.clearCallingIdentity();
5842 try {
5843 Phone phone = getPhone(subscriptionId);
5844 if (phone == null) {
5845 return null;
5846 }
5847 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5848 } finally {
5849 Binder.restoreCallingIdentity(identity);
5850 }
5851 }
5852
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005853 /**
5854 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005855 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005856 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005857 final long identity = Binder.clearCallingIdentity();
5858 try {
5859 Phone phone = getPhone(subId);
5860 if (phone != null) {
5861 return phone.isWifiCallingEnabled();
5862 } else {
5863 return false;
5864 }
5865 } finally {
5866 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005867 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005868 }
5869
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005870 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005871 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005872 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005873 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005874 final long identity = Binder.clearCallingIdentity();
5875 try {
5876 Phone phone = getPhone(subId);
5877 if (phone != null) {
5878 return phone.isVideoEnabled();
5879 } else {
5880 return false;
5881 }
5882 } finally {
5883 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005884 }
5885 }
5886
5887 /**
5888 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5889 * defined in {@link ImsRegistrationImplBase}.
5890 */
5891 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005892 final long identity = Binder.clearCallingIdentity();
5893 try {
5894 Phone phone = getPhone(subId);
5895 if (phone != null) {
5896 return phone.getImsRegistrationTech();
5897 } else {
5898 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5899 }
5900 } finally {
5901 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005902 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005903 }
5904
Stuart Scott8eef64f2015-04-08 15:13:54 -07005905 @Override
5906 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08005907 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005908 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5909 return;
5910 }
5911
Svet Ganovcc087f82015-05-12 20:35:54 -07005912 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005913
Svet Ganovcc087f82015-05-12 20:35:54 -07005914 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005915 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5916 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005917 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005918 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005919 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005920 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5921 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005922 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005923 // There has been issues when Sms raw table somehow stores orphan
5924 // fragments. They lead to garbled message when new fragments come
5925 // in and combined with those stale ones. In case this happens again,
5926 // user can reset all network settings which will clean up this table.
5927 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005928 // Clean up IMS settings as well here.
5929 int slotId = getSlotIndex(subId);
5930 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5931 ImsManager.getInstance(mApp, slotId).factoryReset();
5932 }
Naina Nallurid63128d2019-09-17 14:10:30 -07005933
5934 // Erase modem config if erase modem on network setting is enabled.
5935 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
5936 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
5937 if (configValue != null && Boolean.parseBoolean(configValue)) {
5938 sendEraseModemConfig(getDefaultPhone());
5939 }
Svet Ganovcc087f82015-05-12 20:35:54 -07005940 } finally {
5941 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005942 }
5943 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005944
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005945 private void cleanUpSmsRawTable(Context context) {
5946 ContentResolver resolver = context.getContentResolver();
5947 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5948 resolver.delete(uri, null, null);
5949 }
5950
Narayan Kamath1c496c22015-04-16 14:40:19 +01005951 @Override
chen xu5d3637b2019-01-21 23:31:38 -08005952 public String getSimLocaleForSubscriber(int subId) {
5953 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5954 final Phone phone = getPhone(subId);
5955 if (phone == null) {
5956 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08005957 return null;
chen xu5d3637b2019-01-21 23:31:38 -08005958 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005959 final long identity = Binder.clearCallingIdentity();
5960 try {
chen xu5d3637b2019-01-21 23:31:38 -08005961 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005962 phone.getContext().getOpPackageName(), phone.getContext().getFeatureId());
chen xu6291c472019-02-04 12:55:53 -08005963 if (info == null) {
5964 log("getSimLocaleForSubscriber, inactive subId: " + subId);
5965 return null;
5966 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005967 // Try and fetch the locale from the carrier properties or from the SIM language
5968 // preferences (EF-PL and EF-LI)...
5969 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005970 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08005971 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5972 if (localeFromDefaultSim != null) {
5973 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5974 if (DBG) log("Using locale from subId: " + subId + " locale: "
5975 + localeFromDefaultSim);
5976 return localeFromDefaultSim.toLanguageTag();
5977 } else {
5978 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005979 }
5980 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005981
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005982 // The SIM language preferences only store a language (e.g. fr = French), not an
5983 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5984 // the SIM and carrier preferences does not include a country we add the country
5985 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08005986 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005987 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08005988 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005989 return mccLocale.toLanguageTag();
5990 }
5991
5992 if (DBG) log("No locale found - returning null");
5993 return null;
5994 } finally {
5995 Binder.restoreCallingIdentity(identity);
5996 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005997 }
5998
5999 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006000 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
6001 mApp.getFeatureId());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006002 }
6003
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006004 /**
6005 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6006 */
6007 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006008 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
6009 mApp.getFeatureId());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006010 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006011
Chenjie Yu1ba97252018-01-11 18:16:20 -08006012 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xud78231e2019-09-10 18:49:52 -07006013 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006014
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006015 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006016 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6017 * representing the state of the modem.
6018 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006019 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6020 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006021 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006022 */
6023 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006024 public void requestModemActivityInfo(ResultReceiver result) {
6025 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006026 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006027
6028 final long identity = Binder.clearCallingIdentity();
6029 try {
6030 ModemActivityInfo ret = null;
6031 synchronized (mLastModemActivityInfo) {
6032 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
6033 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07006034 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07006035 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006036 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
Chen Xud78231e2019-09-10 18:49:52 -07006037 int[] txTimeMs = info.getTransmitTimeMillis();
6038 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006039 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Chen Xud78231e2019-09-10 18:49:52 -07006040 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006041 }
6042 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006043 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
6044 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006045 mLastModemActivityInfo.setIdleTimeMillis(
6046 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
Chen Xud78231e2019-09-10 18:49:52 -07006047 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
6048 mLastModemActivityInfo.setReceiveTimeMillis(
6049 info.getReceiveTimeMillis() + mLastModemActivityInfo
6050 .getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006051 }
Chen Xud78231e2019-09-10 18:49:52 -07006052
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006053 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
6054 mLastModemActivityInfo.getSleepTimeMillis(),
6055 mLastModemActivityInfo.getIdleTimeMillis(),
Chen Xud78231e2019-09-10 18:49:52 -07006056 mLastModemActivityInfo.getTransmitTimeMillis(),
6057 mLastModemActivityInfo.getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006058 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006059 Bundle bundle = new Bundle();
6060 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
6061 result.send(0, bundle);
6062 } finally {
6063 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006064 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006065 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006066
Siddharth Rayb8114062018-06-17 15:02:38 -07006067 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6068 // less than total activity duration.
6069 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6070 if (info == null) {
6071 return false;
6072 }
6073 int activityDurationMs =
6074 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6075 int totalTxTimeMs = 0;
Chen Xud78231e2019-09-10 18:49:52 -07006076 int[] txTimeMs = info.getTransmitTimeMillis();
6077 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6078 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006079 }
6080 return (info.isValid()
6081 && (info.getSleepTimeMillis() <= activityDurationMs)
6082 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07006083 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006084 && (totalTxTimeMs <= activityDurationMs));
6085 }
6086
Jack Yu85bd38a2015-11-09 11:34:32 -08006087 /**
6088 * {@hide}
6089 * Returns the service state information on specified subscription.
6090 */
6091 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006092 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6093 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006094 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006095 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006096 return null;
6097 }
6098
Hall Liuf19c44f2018-11-27 14:38:17 -08006099 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6100 LocationAccessPolicy.checkLocationPermission(mApp,
6101 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6102 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006103 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006104 .setCallingPid(Binder.getCallingPid())
6105 .setCallingUid(Binder.getCallingUid())
6106 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006107 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006108 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6109 .build());
6110
6111 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6112 LocationAccessPolicy.checkLocationPermission(mApp,
6113 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6114 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006115 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006116 .setCallingPid(Binder.getCallingPid())
6117 .setCallingUid(Binder.getCallingUid())
6118 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006119 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006120 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6121 .build());
6122 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6123 boolean hasFinePermission =
6124 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6125 boolean hasCoarsePermission =
6126 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6127
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006128 final long identity = Binder.clearCallingIdentity();
6129 try {
6130 final Phone phone = getPhone(subId);
6131 if (phone == null) {
6132 return null;
6133 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006134
Hall Liuf19c44f2018-11-27 14:38:17 -08006135 ServiceState ss = phone.getServiceState();
6136
6137 // Scrub out the location info in ServiceState depending on what level of access
6138 // the caller has.
6139 if (hasFinePermission) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08006140 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
6141 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006142 } finally {
6143 Binder.restoreCallingIdentity(identity);
6144 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006145 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006146
6147 /**
6148 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6149 *
6150 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6151 * voicemail ringtone.
6152 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6153 * PhoneAccount.
6154 */
6155 @Override
6156 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006157 final long identity = Binder.clearCallingIdentity();
6158 try {
6159 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6160 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006161 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006162 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006163
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006164 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6165 } finally {
6166 Binder.restoreCallingIdentity(identity);
6167 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006168 }
6169
6170 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006171 * Sets the per-account voicemail ringtone.
6172 *
6173 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6174 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6175 *
6176 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6177 * voicemail ringtone.
6178 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6179 * PhoneAccount.
6180 */
6181 @Override
6182 public void setVoicemailRingtoneUri(String callingPackage,
6183 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006184 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006185 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006186 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6187 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006188 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6189 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6190 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006191 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006192
6193 final long identity = Binder.clearCallingIdentity();
6194 try {
6195 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6196 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006197 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006198 }
6199 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6200 } finally {
6201 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006202 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006203 }
6204
6205 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006206 * Returns whether vibration is set for voicemail notification in Phone settings.
6207 *
6208 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6209 * voicemail vibration setting.
6210 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6211 */
6212 @Override
6213 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006214 final long identity = Binder.clearCallingIdentity();
6215 try {
6216 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6217 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006218 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006219 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006220
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006221 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6222 } finally {
6223 Binder.restoreCallingIdentity(identity);
6224 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006225 }
6226
Youhan Wange64578a2016-05-02 15:32:42 -07006227 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006228 * Sets the per-account voicemail vibration.
6229 *
6230 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6231 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6232 *
6233 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6234 * voicemail vibration setting.
6235 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6236 * specific PhoneAccount.
6237 */
6238 @Override
6239 public void setVoicemailVibrationEnabled(String callingPackage,
6240 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006241 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006242 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006243 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6244 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006245 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6246 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6247 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006248 }
6249
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006250 final long identity = Binder.clearCallingIdentity();
6251 try {
6252 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6253 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006254 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006255 }
6256 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6257 } finally {
6258 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006259 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006260 }
6261
6262 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006263 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6264 *
6265 * @throws SecurityException if the caller does not have the required permission
6266 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006267 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006268 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006269 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006270 }
6271
6272 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006273 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6274 * permission.
6275 *
6276 * @throws SecurityException if the caller does not have the required permission
6277 */
6278 private void enforceSendSmsPermission() {
6279 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6280 }
6281
6282 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006283 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006284 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006285 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006286 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006287 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006288 final long identity = Binder.clearCallingIdentity();
6289 try {
6290 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006291 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006292 if (componentName == null) {
6293 throw new SecurityException(
6294 "Caller not current active visual voicemail package[null]");
6295 }
6296 String vvmPackage = componentName.getPackageName();
6297 if (!callingPackage.equals(vvmPackage)) {
6298 throw new SecurityException("Caller not current active visual voicemail package["
6299 + vvmPackage + "]");
6300 }
6301 } finally {
6302 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006303 }
6304 }
6305
6306 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006307 * Return the application ID for the app type.
6308 *
6309 * @param subId the subscription ID that this request applies to.
6310 * @param appType the uicc app type.
6311 * @return Application ID for specificied app type, or null if no uicc.
6312 */
6313 @Override
6314 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006315 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006316 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006317
6318 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006319 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006320 if (phone == null) {
6321 return null;
6322 }
6323 String aid = null;
6324 try {
6325 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6326 .getApplicationByType(appType).getAid();
6327 } catch (Exception e) {
6328 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6329 }
6330 return aid;
6331 } finally {
6332 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006333 }
Youhan Wange64578a2016-05-02 15:32:42 -07006334 }
6335
Youhan Wang4001d252016-05-11 10:29:41 -07006336 /**
6337 * Return the Electronic Serial Number.
6338 *
6339 * @param subId the subscription ID that this request applies to.
6340 * @return ESN or null if error.
6341 */
6342 @Override
6343 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006344 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006345 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006346
6347 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006348 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006349 if (phone == null) {
6350 return null;
6351 }
6352 String esn = null;
6353 try {
6354 esn = phone.getEsn();
6355 } catch (Exception e) {
6356 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6357 }
6358 return esn;
6359 } finally {
6360 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006361 }
Youhan Wang4001d252016-05-11 10:29:41 -07006362 }
6363
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006364 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006365 * Return the Preferred Roaming List Version.
6366 *
6367 * @param subId the subscription ID that this request applies to.
6368 * @return PRLVersion or null if error.
6369 */
6370 @Override
6371 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006372 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006373 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006374
6375 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006376 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006377 if (phone == null) {
6378 return null;
6379 }
6380 String cdmaPrlVersion = null;
6381 try {
6382 cdmaPrlVersion = phone.getCdmaPrlVersion();
6383 } catch (Exception e) {
6384 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6385 }
6386 return cdmaPrlVersion;
6387 } finally {
6388 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006389 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006390 }
6391
6392 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006393 * Get snapshot of Telephony histograms
6394 * @return List of Telephony histograms
6395 * @hide
6396 */
6397 @Override
6398 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006399 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6400 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006401
6402 final long identity = Binder.clearCallingIdentity();
6403 try {
6404 return RIL.getTelephonyRILTimingHistograms();
6405 } finally {
6406 Binder.restoreCallingIdentity(identity);
6407 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006408 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006409
6410 /**
6411 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006412 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6413 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006414 * Require system privileges. In the future we may add this to carrier APIs.
6415 *
Michele Berionne482f8202018-11-27 18:57:59 -08006416 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006417 */
6418 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006419 @TelephonyManager.SetCarrierRestrictionResult
6420 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006421 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006422 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006423
Michele Berionne482f8202018-11-27 18:57:59 -08006424 if (carrierRestrictionRules == null) {
6425 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08006426 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006427
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006428 final long identity = Binder.clearCallingIdentity();
6429 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006430 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07006431 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006432 } finally {
6433 Binder.restoreCallingIdentity(identity);
6434 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006435 }
6436
6437 /**
6438 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006439 * Get the allowed carrier list and the excluded carrier list, including the priority between
6440 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006441 * Require system privileges. In the future we may add this to carrier APIs.
6442 *
Michele Berionne482f8202018-11-27 18:57:59 -08006443 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07006444 */
6445 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006446 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006447 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07006448 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006449
6450 final long identity = Binder.clearCallingIdentity();
6451 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006452 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
6453 if (response instanceof CarrierRestrictionRules) {
6454 return (CarrierRestrictionRules) response;
6455 }
6456 // Response is an Exception of some kind,
6457 // which is signalled to the user as a NULL retval
6458 return null;
6459 } catch (Exception e) {
6460 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
6461 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006462 } finally {
6463 Binder.restoreCallingIdentity(identity);
6464 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006465 }
6466
fionaxu59545b42016-05-25 15:53:37 -07006467 /**
6468 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
6469 * @param subId the subscription ID that this action applies to.
6470 * @param enabled control enable or disable metered apns.
6471 * {@hide}
6472 */
6473 @Override
6474 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
6475 enforceModifyPermission();
6476 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006477
6478 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006479 if (phone == null) {
6480 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
6481 return;
6482 }
6483 try {
6484 phone.carrierActionSetMeteredApnsEnabled(enabled);
6485 } catch (Exception e) {
6486 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006487 } finally {
6488 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006489 }
6490 }
6491
6492 /**
6493 * Action set from carrier signalling broadcast receivers to enable/disable radio
6494 * @param subId the subscription ID that this action applies to.
6495 * @param enabled control enable or disable radio.
6496 * {@hide}
6497 */
6498 @Override
6499 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
6500 enforceModifyPermission();
6501 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006502
6503 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006504 if (phone == null) {
6505 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
6506 return;
6507 }
6508 try {
6509 phone.carrierActionSetRadioEnabled(enabled);
6510 } catch (Exception e) {
6511 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006512 } finally {
6513 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006514 }
6515 }
6516
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006517 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006518 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6519 * network status based on which carrier apps could apply actions accordingly,
6520 * enable/disable default url handler for example.
6521 *
6522 * @param subId the subscription ID that this action applies to.
6523 * @param report control start/stop reporting the default network status.
6524 * {@hide}
6525 */
6526 @Override
6527 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6528 enforceModifyPermission();
6529 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006530
6531 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006532 if (phone == null) {
6533 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6534 return;
6535 }
6536 try {
6537 phone.carrierActionReportDefaultNetworkStatus(report);
6538 } catch (Exception e) {
6539 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006540 } finally {
6541 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006542 }
6543 }
6544
6545 /**
fionaxud9622282017-07-17 17:51:30 -07006546 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6547 * @param subId the subscription ID that this action applies to.
6548 * {@hide}
6549 */
6550 @Override
6551 public void carrierActionResetAll(int subId) {
6552 enforceModifyPermission();
6553 final Phone phone = getPhone(subId);
6554 if (phone == null) {
6555 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6556 return;
6557 }
6558 try {
6559 phone.carrierActionResetAll();
6560 } catch (Exception e) {
6561 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6562 }
6563 }
6564
6565 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006566 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6567 * bug report is being generated.
6568 */
6569 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006570 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006571 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6572 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006573 writer.println("Permission Denial: can't dump Phone from pid="
6574 + Binder.getCallingPid()
6575 + ", uid=" + Binder.getCallingUid()
6576 + "without permission "
6577 + android.Manifest.permission.DUMP);
6578 return;
6579 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006580 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006581 }
Jack Yueb89b242016-06-22 13:27:47 -07006582
Brad Ebingerdac2f002018-04-03 15:17:52 -07006583 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08006584 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
6585 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
6586 @NonNull String[] args) {
6587 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
6588 this, in.getFileDescriptor(), out.getFileDescriptor(),
6589 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07006590 }
6591
Jack Yueb89b242016-06-22 13:27:47 -07006592 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006593 * Get aggregated video call data usage since boot.
6594 *
6595 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6596 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006597 * {@hide}
6598 */
6599 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006600 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006601 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6602 null);
6603
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006604 final long identity = Binder.clearCallingIdentity();
6605 try {
6606 // NetworkStatsService keeps tracking the active network interface and identity. It
6607 // records the delta with the corresponding network identity.
6608 // We just return the total video call data usage snapshot since boot.
6609 Phone phone = getPhone(subId);
6610 if (phone != null) {
6611 return phone.getVtDataUsage(perUidStats);
6612 }
6613 return null;
6614 } finally {
6615 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006616 }
Jack Yueb89b242016-06-22 13:27:47 -07006617 }
Jack Yu75ab2952016-07-08 14:29:33 -07006618
6619 /**
6620 * Policy control of data connection. Usually used when data limit is passed.
6621 * @param enabled True if enabling the data, otherwise disabling.
6622 * @param subId Subscription index
6623 * {@hide}
6624 */
6625 @Override
6626 public void setPolicyDataEnabled(boolean enabled, int subId) {
6627 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006628
6629 final long identity = Binder.clearCallingIdentity();
6630 try {
6631 Phone phone = getPhone(subId);
6632 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006633 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006634 }
6635 } finally {
6636 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006637 }
6638 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006639
6640 /**
6641 * Get Client request stats
6642 * @return List of Client Request Stats
6643 * @hide
6644 */
6645 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006646 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
6647 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006648 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006649 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006650 return null;
6651 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006652 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006653
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006654 final long identity = Binder.clearCallingIdentity();
6655 try {
6656 if (phone != null) {
6657 return phone.getClientRequestStats();
6658 }
6659
6660 return null;
6661 } finally {
6662 Binder.restoreCallingIdentity(identity);
6663 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006664 }
6665
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006666 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006667 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006668 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006669 }
Jack Yueb4124c2017-02-16 15:32:43 -08006670
6671 /**
Grace Chen70990072017-03-24 17:21:30 -07006672 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006673 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006674 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006675 * @param state State of SIM (power down, power up, pass through)
6676 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6677 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6678 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006679 *
6680 **/
6681 @Override
Grace Chen70990072017-03-24 17:21:30 -07006682 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006683 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006684 Phone phone = PhoneFactory.getPhone(slotIndex);
6685
vagdeviaf9a5b92018-08-15 16:01:53 -07006686 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6687
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006688 final long identity = Binder.clearCallingIdentity();
6689 try {
6690 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006691 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006692 }
6693 } finally {
6694 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006695 }
6696 }
Shuo Qiandd210312017-04-12 22:11:33 +00006697
Tyler Gunn65d45c22017-06-05 11:22:26 -07006698 private boolean isUssdApiAllowed(int subId) {
6699 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006700 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006701 if (configManager == null) {
6702 return false;
6703 }
6704 PersistableBundle pb = configManager.getConfigForSubId(subId);
6705 if (pb == null) {
6706 return false;
6707 }
6708 return pb.getBoolean(
6709 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6710 }
6711
Shuo Qiandd210312017-04-12 22:11:33 +00006712 /**
6713 * Check if phone is in emergency callback mode
6714 * @return true if phone is in emergency callback mode
6715 * @param subId sub id
6716 */
goneil9c5f4872017-12-05 14:07:56 -08006717 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006718 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006719 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006720 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006721
6722 final long identity = Binder.clearCallingIdentity();
6723 try {
6724 if (phone != null) {
6725 return phone.isInEcm();
6726 } else {
6727 return false;
6728 }
6729 } finally {
6730 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006731 }
6732 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006733
6734 /**
6735 * Get the current signal strength information for the given subscription.
6736 * Because this information is not updated when the device is in a low power state
6737 * it should not be relied-upon to be current.
6738 * @param subId Subscription index
6739 * @return the most recent cached signal strength info from the modem
6740 */
6741 @Override
6742 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006743 final long identity = Binder.clearCallingIdentity();
6744 try {
6745 Phone p = getPhone(subId);
6746 if (p == null) {
6747 return null;
6748 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006749
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006750 return p.getSignalStrength();
6751 } finally {
6752 Binder.restoreCallingIdentity(identity);
6753 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006754 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006755
Pengquan Meng77b7f132018-08-22 14:49:57 -07006756 /**
Chen Xuf792fd62018-10-17 17:54:36 +00006757 * Get the current modem radio state for the given slot.
6758 * @param slotIndex slot index.
6759 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006760 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00006761 * @return the current radio power state from the modem
6762 */
6763 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006764 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00006765 Phone phone = PhoneFactory.getPhone(slotIndex);
6766 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006767 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
6768 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00006769 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6770 }
6771
6772 final long identity = Binder.clearCallingIdentity();
6773 try {
6774 return phone.getRadioPowerState();
6775 } finally {
6776 Binder.restoreCallingIdentity(identity);
6777 }
6778 }
6779 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6780 }
6781
6782 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07006783 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6784 *
6785 * <p>Requires one of the following permissions:
6786 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6787 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6788 * privileges.
6789 *
6790 * @param subId subscription id
6791 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6792 * {@code false}.
6793 */
6794 @Override
6795 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006796 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6797 null /* message */);
6798
Pengquan Menga1bb6272018-09-06 09:59:22 -07006799 boolean isEnabled = false;
6800 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07006801 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006802 Phone phone = getPhone(subId);
6803 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006804 } catch (Exception e) {
6805 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6806 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07006807 } finally {
6808 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006809 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006810 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006811 }
6812
6813
6814 /**
6815 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6816 *
6817 * <p> Requires permission:
6818 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6819 * privileges.
6820 *
6821 * @param subId subscription id
6822 * @param isEnabled {@code true} means enable, {@code false} means disable.
6823 */
6824 @Override
6825 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006826 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6827 mApp, subId, "setDataRoamingEnabled");
6828
Pengquan Menga1bb6272018-09-06 09:59:22 -07006829 final long identity = Binder.clearCallingIdentity();
6830 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006831 Phone phone = getPhone(subId);
6832 if (phone != null) {
6833 phone.setDataRoamingEnabled(isEnabled);
6834 }
6835 } finally {
6836 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006837 }
6838 }
6839
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006840 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006841 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08006842 TelephonyPermissions
6843 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07006844 mApp, subId, "isManualNetworkSelectionAllowed");
6845
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006846 boolean isAllowed = true;
6847 final long identity = Binder.clearCallingIdentity();
6848 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006849 Phone phone = getPhone(subId);
6850 if (phone != null) {
6851 isAllowed = phone.isCspPlmnEnabled();
6852 }
6853 } finally {
6854 Binder.restoreCallingIdentity(identity);
6855 }
6856 return isAllowed;
6857 }
6858
6859 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006860 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006861 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08006862 try {
6863 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07006864 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08006865 } catch (SecurityException e) {
6866 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6867 // has carrier privileges on an active UICC
6868 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6869 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006870 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08006871 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006872 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006873
6874 final long identity = Binder.clearCallingIdentity();
6875 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006876 UiccController uiccController = UiccController.getInstance();
6877 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07006878 if (hasReadPermission) {
6879 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006880 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07006881
6882 // Remove private info if the caller doesn't have access
6883 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6884 for (UiccCardInfo cardInfo : cardInfos) {
6885 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6886 // is available
6887 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
6888 if (card == null || card.getUiccProfile() == null) {
6889 // assume no access if the card or profile is unavailable
6890 filteredInfos.add(cardInfo.getUnprivileged());
6891 continue;
6892 }
6893 UiccProfile profile = card.getUiccProfile();
6894 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6895 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6896 filteredInfos.add(cardInfo);
6897 } else {
6898 filteredInfos.add(cardInfo.getUnprivileged());
6899 }
6900 }
6901 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08006902 } finally {
6903 Binder.restoreCallingIdentity(identity);
6904 }
6905 }
6906
6907 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006908 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006909 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006910
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006911 final long identity = Binder.clearCallingIdentity();
6912 try {
6913 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6914 if (slots == null) {
6915 Rlog.i(LOG_TAG, "slots is null.");
6916 return null;
6917 }
6918
6919 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6920 for (int i = 0; i < slots.length; i++) {
6921 UiccSlot slot = slots[i];
6922 if (slot == null) {
6923 continue;
6924 }
6925
Jordan Liu7be7e652019-05-06 18:55:02 +00006926 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006927 UiccCard card = slot.getUiccCard();
6928 if (card != null) {
6929 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00006930 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07006931 cardId = slot.getEid();
6932 if (TextUtils.isEmpty(cardId)) {
6933 cardId = slot.getIccId();
6934 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006935 }
6936
Jordan Liu857451f2019-05-09 16:35:35 -07006937 if (cardId != null) {
6938 // if cardId is an ICCID, strip off trailing Fs before exposing to user
6939 // if cardId is an EID, it's all digits so this is fine
6940 cardId = IccUtils.stripTrailingFs(cardId);
6941 }
6942
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006943 int cardState = 0;
6944 switch (slot.getCardState()) {
6945 case CARDSTATE_ABSENT:
6946 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6947 break;
6948 case CARDSTATE_PRESENT:
6949 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6950 break;
6951 case CARDSTATE_ERROR:
6952 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6953 break;
6954 case CARDSTATE_RESTRICTED:
6955 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6956 break;
6957 default:
6958 break;
6959
6960 }
6961
6962 infos[i] = new UiccSlotInfo(
6963 slot.isActive(),
6964 slot.isEuicc(),
6965 cardId,
6966 cardState,
6967 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08006968 slot.isExtendedApduSupported(),
6969 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006970 }
6971 return infos;
6972 } finally {
6973 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006974 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006975 }
6976
6977 @Override
6978 public boolean switchSlots(int[] physicalSlots) {
6979 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006980
6981 final long identity = Binder.clearCallingIdentity();
6982 try {
6983 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6984 } finally {
6985 Binder.restoreCallingIdentity(identity);
6986 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006987 }
Jack Yu4c988042018-02-27 15:30:01 -08006988
6989 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006990 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006991 final long identity = Binder.clearCallingIdentity();
6992 try {
6993 return UiccController.getInstance().getCardIdForDefaultEuicc();
6994 } finally {
6995 Binder.restoreCallingIdentity(identity);
6996 }
6997 }
6998
6999 @Override
Jack Yu4c988042018-02-27 15:30:01 -08007000 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
7001 enforceModifyPermission();
7002 final Phone phone = getPhone(subId);
7003 if (phone == null) {
7004 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
7005 return;
7006 }
7007
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007008 final long identity = Binder.clearCallingIdentity();
7009 try {
7010 phone.setRadioIndicationUpdateMode(filters, mode);
7011 } finally {
7012 Binder.restoreCallingIdentity(identity);
7013 }
Jack Yu4c988042018-02-27 15:30:01 -08007014 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07007015
7016 /**
goneil47ffb6e2018-04-06 15:40:58 -07007017 * A test API to reload the UICC profile.
7018 *
7019 * <p>Requires that the calling app has permission
7020 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7021 * @hide
7022 */
7023 @Override
7024 public void refreshUiccProfile(int subId) {
7025 enforceModifyPermission();
7026
7027 final long identity = Binder.clearCallingIdentity();
7028 try {
7029 Phone phone = getPhone(subId);
7030 if (phone == null) {
7031 return;
7032 }
7033 UiccCard uiccCard = phone.getUiccCard();
7034 if (uiccCard == null) {
7035 return;
7036 }
7037 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7038 if (uiccProfile == null) {
7039 return;
7040 }
7041 uiccProfile.refresh();
7042 } finally {
7043 Binder.restoreCallingIdentity(identity);
7044 }
7045 }
7046
7047 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007048 * Returns false if the mobile data is disabled by default, otherwise return true.
7049 */
7050 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007051 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007052 }
7053
7054 /**
7055 * Returns true if the data roaming is enabled by default, i.e the system property
7056 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7057 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7058 */
7059 private boolean getDefaultDataRoamingEnabled(int subId) {
7060 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007061 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Inseob Kim14bb3d02018-12-13 17:11:34 +09007062 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007063 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7064 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7065 return isDataRoamingEnabled;
7066 }
7067
7068 /**
7069 * Returns the default network type for the given {@code subId}, if the default network type is
7070 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7071 */
7072 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007073 List<Integer> list = TelephonyProperties.default_network();
7074 int phoneId = mSubscriptionController.getPhoneId(subId);
7075 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7076 return list.get(phoneId);
7077 }
7078 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007079 }
fionaxua13278b2018-03-21 00:08:13 -07007080
7081 @Override
7082 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007083 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007084 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007085
7086 final long identity = Binder.clearCallingIdentity();
7087 try {
7088 final Phone phone = getPhone(subId);
7089 if (phone == null) {
7090 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7091 return;
7092 }
chen xueaba88a2019-03-15 13:15:10 -07007093 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7094 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007095 } finally {
7096 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007097 }
fionaxua13278b2018-03-21 00:08:13 -07007098 }
7099
7100 @Override
7101 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007102 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007103
7104 final long identity = Binder.clearCallingIdentity();
7105 try {
7106 final Phone phone = getPhone(subId);
7107 if (phone == null) {
7108 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7109 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7110 }
7111 return phone.getCarrierIdListVersion();
7112 } finally {
7113 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007114 }
fionaxua13278b2018-03-21 00:08:13 -07007115 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007116
7117 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007118 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7119 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007120 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007121 mApp, subId, callingPackage, callingFeatureId,
7122 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007123 return -1;
7124 }
7125
7126 final long identity = Binder.clearCallingIdentity();
7127 try {
7128 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7129 } finally {
7130 Binder.restoreCallingIdentity(identity);
7131 }
7132 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007133
7134 @Override
7135 public int getCdmaRoamingMode(int subId) {
7136 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7137 mApp, subId, "getCdmaRoamingMode");
7138
7139 final long identity = Binder.clearCallingIdentity();
7140 try {
7141 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7142 } finally {
7143 Binder.restoreCallingIdentity(identity);
7144 }
7145 }
7146
7147 @Override
7148 public boolean setCdmaRoamingMode(int subId, int mode) {
7149 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7150 mApp, subId, "setCdmaRoamingMode");
7151
7152 final long identity = Binder.clearCallingIdentity();
7153 try {
7154 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7155 } finally {
7156 Binder.restoreCallingIdentity(identity);
7157 }
7158 }
7159
7160 @Override
7161 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7162 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7163 mApp, subId, "setCdmaSubscriptionMode");
7164
7165 final long identity = Binder.clearCallingIdentity();
7166 try {
7167 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7168 } finally {
7169 Binder.restoreCallingIdentity(identity);
7170 }
7171 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007172
sqianc5eccab2018-10-19 18:46:41 -07007173 @Override
sqian8c685422019-02-22 15:55:18 -08007174 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007175 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007176 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007177 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7178 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007179 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7180 }
7181 final long identity = Binder.clearCallingIdentity();
7182 try {
sqian854d44b2018-12-12 16:48:18 -08007183 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7184 for (Phone phone: PhoneFactory.getPhones()) {
7185 if (phone.getEmergencyNumberTracker() != null
7186 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7187 emergencyNumberListInternal.put(
7188 phone.getSubId(),
7189 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7190 }
sqian11b7a0e2018-12-05 18:48:28 -08007191 }
sqian854d44b2018-12-12 16:48:18 -08007192 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007193 } finally {
7194 Binder.restoreCallingIdentity(identity);
7195 }
sqianc5eccab2018-10-19 18:46:41 -07007196 }
7197
7198 @Override
sqian8c685422019-02-22 15:55:18 -08007199 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007200 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007201 if (!exactMatch) {
7202 TelephonyPermissions
7203 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007204 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007205 }
7206 final long identity = Binder.clearCallingIdentity();
7207 try {
sqian854d44b2018-12-12 16:48:18 -08007208 for (Phone phone: PhoneFactory.getPhones()) {
7209 if (phone.getEmergencyNumberTracker() != null
7210 && phone.getEmergencyNumberTracker() != null) {
7211 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7212 number, exactMatch)) {
7213 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007214 }
7215 }
sqian11b7a0e2018-12-05 18:48:28 -08007216 }
7217 return false;
7218 } finally {
7219 Binder.restoreCallingIdentity(identity);
7220 }
7221 }
7222
sqianf4ca7ed2019-01-15 18:32:07 -08007223 /**
7224 * Update emergency number list for test mode.
7225 */
7226 @Override
7227 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7228 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7229 "updateEmergencyNumberListTestMode");
7230
7231 final long identity = Binder.clearCallingIdentity();
7232 try {
7233 for (Phone phone: PhoneFactory.getPhones()) {
7234 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7235 if (tracker != null) {
7236 tracker.executeEmergencyNumberTestModeCommand(action, num);
7237 }
7238 }
7239 } finally {
7240 Binder.restoreCallingIdentity(identity);
7241 }
7242 }
7243
7244 /**
7245 * Get the full emergency number list for test mode.
7246 */
7247 @Override
7248 public List<String> getEmergencyNumberListTestMode() {
7249 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7250 "getEmergencyNumberListTestMode");
7251
7252 final long identity = Binder.clearCallingIdentity();
7253 try {
7254 Set<String> emergencyNumbers = new HashSet<>();
7255 for (Phone phone: PhoneFactory.getPhones()) {
7256 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7257 if (tracker != null) {
7258 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7259 emergencyNumbers.add(num.getNumber());
7260 }
7261 }
7262 }
7263 return new ArrayList<>(emergencyNumbers);
7264 } finally {
7265 Binder.restoreCallingIdentity(identity);
7266 }
7267 }
7268
chen xud6b45bd2018-10-30 22:27:10 -07007269 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08007270 public int getEmergencyNumberDbVersion(int subId) {
7271 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7272
7273 final long identity = Binder.clearCallingIdentity();
7274 try {
7275 final Phone phone = getPhone(subId);
7276 if (phone == null) {
7277 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7278 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7279 }
7280 return phone.getEmergencyNumberDbVersion();
7281 } finally {
7282 Binder.restoreCallingIdentity(identity);
7283 }
7284 }
7285
7286 @Override
7287 public void notifyOtaEmergencyNumberDbInstalled() {
7288 enforceModifyPermission();
7289
7290 final long identity = Binder.clearCallingIdentity();
7291 try {
7292 for (Phone phone: PhoneFactory.getPhones()) {
7293 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7294 if (tracker != null) {
7295 tracker.updateOtaEmergencyNumberDatabase();
7296 }
7297 }
7298 } finally {
7299 Binder.restoreCallingIdentity(identity);
7300 }
7301 }
7302
7303 @Override
7304 public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) {
7305 enforceActiveEmergencySessionPermission();
7306
7307 final long identity = Binder.clearCallingIdentity();
7308 try {
7309 for (Phone phone: PhoneFactory.getPhones()) {
7310 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7311 if (tracker != null) {
7312 tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath);
7313 }
7314 }
7315 } finally {
7316 Binder.restoreCallingIdentity(identity);
7317 }
7318 }
7319
7320 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007321 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7322 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7323 Phone phone = getPhone(subId);
7324 if (phone == null) {
7325 return null;
7326 }
7327 final long identity = Binder.clearCallingIdentity();
7328 try {
7329 UiccProfile profile = UiccController.getInstance()
7330 .getUiccProfileForPhone(phone.getPhoneId());
7331 if (profile != null) {
7332 return profile.getCertsFromCarrierPrivilegeAccessRules();
7333 }
7334 } finally {
7335 Binder.restoreCallingIdentity(identity);
7336 }
7337 return null;
7338 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007339
7340 /**
7341 * Enable or disable a modem stack.
7342 */
7343 @Override
7344 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7345 enforceModifyPermission();
7346
7347 final long identity = Binder.clearCallingIdentity();
7348 try {
7349 Phone phone = PhoneFactory.getPhone(slotIndex);
7350 if (phone == null) {
7351 return false;
7352 } else {
7353 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7354 }
7355 } finally {
7356 Binder.restoreCallingIdentity(identity);
7357 }
7358 }
Michelecea4cf22018-12-21 15:00:11 -08007359
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007360 /**
7361 * Whether a modem stack is enabled or not.
7362 */
7363 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007364 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
7365 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007366 Phone phone = PhoneFactory.getPhone(slotIndex);
7367 if (phone == null) return false;
7368
7369 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007370 mApp, phone.getSubId(), callingPackage, callingFeatureId,
7371 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007372 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7373 }
7374
7375 final long identity = Binder.clearCallingIdentity();
7376 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007377 try {
7378 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7379 } catch (NoSuchElementException ex) {
7380 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7381 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007382 } finally {
7383 Binder.restoreCallingIdentity(identity);
7384 }
7385 }
7386
Michelecea4cf22018-12-21 15:00:11 -08007387 @Override
Michele0ea7d782019-03-19 14:58:42 -07007388 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007389 enforceModifyPermission();
7390
7391 final long identity = Binder.clearCallingIdentity();
7392 try {
7393 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007394 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007395 .commit();
7396 } finally {
7397 Binder.restoreCallingIdentity(identity);
7398 }
7399 }
7400
7401 @Override
Michele0ea7d782019-03-19 14:58:42 -07007402 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007403 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08007404 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007405 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
7406 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07007407 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007408 }
Michelecea4cf22018-12-21 15:00:11 -08007409
7410 final long identity = Binder.clearCallingIdentity();
7411 try {
Michele0ea7d782019-03-19 14:58:42 -07007412 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007413 } finally {
7414 Binder.restoreCallingIdentity(identity);
7415 }
7416 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007417
Michele0ea7d782019-03-19 14:58:42 -07007418 @TelephonyManager.IsMultiSimSupportedResult
7419 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007420 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7421 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7422 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007423 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7424 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007425 }
7426 // Check if the hardware supports multisim functionality. If usage of multisim is not
7427 // supported by the modem, indicate that it is restricted.
7428 PhoneCapability staticCapability =
7429 mPhoneConfigurationManager.getStaticPhoneCapability();
7430 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007431 loge("isMultiSimSupportedInternal: no static configuration available");
7432 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007433 }
7434 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007435 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7436 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007437 }
7438 // Check if support of multiple SIMs is restricted by carrier
7439 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07007440 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007441 }
7442
Michele0ea7d782019-03-19 14:58:42 -07007443 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007444 }
7445
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007446 /**
7447 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007448 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7449 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7450 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007451 * @param numOfSims number of active sims we want to switch to
7452 */
7453 @Override
7454 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007455 if (numOfSims == 1) {
7456 enforceModifyPermission();
7457 } else {
7458 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7459 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
7460 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007461 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08007462
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007463 try {
Michele30b57b22019-03-01 12:01:14 -08007464 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07007465 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08007466 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
7467 return;
7468 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007469 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7470 } finally {
7471 Binder.restoreCallingIdentity(identity);
7472 }
7473 }
7474
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09007475 @Override
7476 public boolean isApplicationOnUicc(int subId, int appType) {
7477 enforceReadPrivilegedPermission("isApplicationOnUicc");
7478 Phone phone = getPhone(subId);
7479 if (phone == null) {
7480 return false;
7481 }
7482 final long identity = Binder.clearCallingIdentity();
7483 try {
7484 UiccCard uiccCard = phone.getUiccCard();
7485 if (uiccCard == null) {
7486 return false;
7487 }
7488 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7489 if (uiccProfile == null) {
7490 return false;
7491 }
7492 if (TelephonyManager.APPTYPE_SIM <= appType
7493 && appType <= TelephonyManager.APPTYPE_ISIM) {
7494 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
7495 }
7496 return false;
7497 } finally {
7498 Binder.restoreCallingIdentity(identity);
7499 }
7500 }
7501
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007502 /**
chen xub4baa772019-04-03 10:23:41 -07007503 * Get whether making changes to modem configurations will trigger reboot.
7504 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007505 */
7506 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007507 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
7508 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07007509 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007510 mApp, subId, callingPackage, callingFeatureId,
7511 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07007512 return false;
7513 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007514 final long identity = Binder.clearCallingIdentity();
7515 try {
7516 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
7517 } finally {
7518 Binder.restoreCallingIdentity(identity);
7519 }
7520 }
7521
Nathan Harold29f5f052019-02-15 13:41:57 -08007522 private void updateModemStateMetrics() {
7523 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
7524 // TODO: check the state for each modem if the api is ready.
7525 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
7526 }
7527
Pengquan Meng3889a572019-01-23 11:16:29 -08007528 @Override
7529 public int[] getSlotsMapping() {
7530 enforceReadPrivilegedPermission("getSlotsMapping");
7531
7532 final long identity = Binder.clearCallingIdentity();
7533 try {
7534 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
7535 // All logical slots should have a mapping to a physical slot.
7536 int[] logicalSlotsMapping = new int[phoneCount];
7537 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
7538 for (int i = 0; i < slotInfos.length; i++) {
7539 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
7540 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
7541 }
7542 }
7543 return logicalSlotsMapping;
7544 } finally {
7545 Binder.restoreCallingIdentity(identity);
7546 }
7547 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007548
7549 /**
7550 * Get the IRadio HAL Version
7551 */
7552 @Override
7553 public int getRadioHalVersion() {
7554 Phone phone = getDefaultPhone();
7555 if (phone == null) return -1;
7556 HalVersion hv = phone.getHalVersion();
7557 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7558 return hv.major * 100 + hv.minor;
7559 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007560
7561 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007562 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7563 * corresponding network requests on a subId.
7564 *
7565 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007566 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007567 * 2) APN is un-metered for this subscription, or
7568 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
changbettyd5c246e2019-12-24 15:40:37 +08007569 * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on.
Malcolm Chene5ad5792019-04-18 13:51:02 -07007570 *
7571 * @return whether data is allowed for a apn type.
7572 *
7573 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007574 */
7575 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007576 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07007577 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
7578 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007579
7580 // Now that all security checks passes, perform the operation as ourselves.
7581 final long identity = Binder.clearCallingIdentity();
7582 try {
7583 Phone phone = getPhone(subId);
7584 if (phone == null) return false;
7585
Jack Yu41407ee2019-05-13 16:54:09 -07007586 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07007587 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7588 } finally {
7589 Binder.restoreCallingIdentity(identity);
7590 }
7591 }
7592
7593 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07007594 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07007595 enforceReadPrivilegedPermission("isApnMetered");
7596
7597 // Now that all security checks passes, perform the operation as ourselves.
7598 final long identity = Binder.clearCallingIdentity();
7599 try {
7600 Phone phone = getPhone(subId);
7601 if (phone == null) return true; // By default return true.
7602
Jack Yu41407ee2019-05-13 16:54:09 -07007603 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007604 } finally {
7605 Binder.restoreCallingIdentity(identity);
7606 }
7607 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007608
7609 @Override
changbetty7157e9e2019-12-06 18:16:37 +08007610 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
7611 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
7612 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
7613 if (iccRecords == null) {
7614 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
7615 return false;
7616 }
7617 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
7618 }
7619
7620 @Override
Brad Ebingera63db5f2019-04-23 16:31:13 -07007621 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
7622 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
7623 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
7624 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
7625 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
7626 }
7627 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
7628 Intent intent = new Intent();
7629 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
7630 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7631 // Bring up choose default SMS subscription dialog right now
7632 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
7633 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
7634 mApp.startActivity(intent);
7635 }
chen xud5ca2d52019-05-28 15:20:57 -07007636
7637 @Override
7638 public String getMmsUAProfUrl(int subId) {
7639 //TODO investigate if this API should require proper permission check in R b/133791609
7640 final long identity = Binder.clearCallingIdentity();
7641 try {
7642 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7643 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
7644 } finally {
7645 Binder.restoreCallingIdentity(identity);
7646 }
7647 }
7648
7649 @Override
7650 public String getMmsUserAgent(int subId) {
7651 //TODO investigate if this API should require proper permission check in R b/133791609
7652 final long identity = Binder.clearCallingIdentity();
7653 try {
7654 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7655 .getString(com.android.internal.R.string.config_mms_user_agent);
7656 } finally {
7657 Binder.restoreCallingIdentity(identity);
7658 }
7659 }
Jack Yub07d4972019-05-28 16:12:25 -07007660
7661 @Override
7662 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
7663 enforceModifyPermission();
7664
7665 // Now that all security checks passes, perform the operation as ourselves.
7666 final long identity = Binder.clearCallingIdentity();
7667 try {
7668 Phone phone = getPhone(subId);
7669 if (phone == null) return false;
7670
7671 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
7672 } finally {
7673 Binder.restoreCallingIdentity(identity);
7674 }
7675 }
7676
7677 @Override
7678 public boolean isDataAllowedInVoiceCall(int subId) {
7679 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
7680
7681 // Now that all security checks passes, perform the operation as ourselves.
7682 final long identity = Binder.clearCallingIdentity();
7683 try {
7684 Phone phone = getPhone(subId);
7685 if (phone == null) return false;
7686
7687 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
7688 } finally {
7689 Binder.restoreCallingIdentity(identity);
7690 }
7691 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07007692
changbettyd5c246e2019-12-24 15:40:37 +08007693 @Override
7694 public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) {
7695 enforceModifyPermission();
7696
7697 // Now that all security checks passes, perform the operation as ourselves.
7698 final long identity = Binder.clearCallingIdentity();
7699 try {
7700 Phone phone = getPhone(subId);
7701 if (phone == null) return false;
7702
7703 return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow);
7704 } finally {
7705 Binder.restoreCallingIdentity(identity);
7706 }
7707 }
7708
Tyler Gunn7bcdc742019-10-04 15:56:59 -07007709 /**
7710 * Updates whether conference event pacakge handling is enabled.
7711 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
7712 * otherwise.
7713 */
7714 @Override
7715 public void setCepEnabled(boolean isCepEnabled) {
7716 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
7717
7718 final long identity = Binder.clearCallingIdentity();
7719 try {
7720 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
7721 for (Phone phone : PhoneFactory.getPhones()) {
7722 Phone defaultPhone = phone.getImsPhone();
7723 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7724 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7725 ImsPhoneCallTracker imsPhoneCallTracker =
7726 (ImsPhoneCallTracker) imsPhone.getCallTracker();
7727 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
7728 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
7729 + imsPhone.getMsisdn());
7730 }
7731 }
7732 } finally {
7733 Binder.restoreCallingIdentity(identity);
7734 }
7735 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007736}